Skip to content

Commit

Permalink
ci: actions changed golangci lint (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
baerwang authored Jan 22, 2025
1 parent b39ccaa commit e77c3aa
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 61 deletions.
1 change: 0 additions & 1 deletion .github/actions/review-dog
Submodule review-dog deleted from c9fac8
7 changes: 4 additions & 3 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.
#
name: reviewdog
on: [pull_request]
on: [ pull_request ]
jobs:
golangci-lint:
name: review
Expand All @@ -28,7 +28,8 @@ jobs:
with:
persist-credentials: false
submodules: true

- name: golangci-lint
uses: ./.github/actions/review-dog
uses: golangci/golangci-lint-action@v6
with:
golangci_lint_flags: "--timeout=10m"
args: --timeout=10m
4 changes: 2 additions & 2 deletions configcenter/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ type (
Remote bool
DataId string
Group string
path string
parser string
path string // nolint:unused
parser string // nolint:unused
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ func (asl *applicationServiceListener) WatchAndHandle() {
return
}
if failTimes > MaxFailTimes {
logger.Errorf("Error happens on (path{%s}) exceed max fail times: %v,so exit listen",
asl.servicePath, MaxFailTimes)
logger.Errorf(
"Error happens on (path{%s}) exceed max fail times: %v,so exit listen",
asl.servicePath, MaxFailTimes,
)
return
}
delayTimer.Reset(ConnDelay * time.Duration(failTimes))
Expand All @@ -113,8 +115,10 @@ func (asl *applicationServiceListener) waitEventAndHandlePeriod(children []strin
case <-ticker.C:
asl.handleEvent(children)
case zkEvent := <-e:
logger.Warnf("get a zookeeper e{type:%s, server:%s, path:%s, state:%d-%s, err:%s}",
zkEvent.Type.String(), zkEvent.Server, zkEvent.Path, zkEvent.State, zookeeper.StateToString(zkEvent.State), zkEvent.Err)
logger.Warnf(
"get a zookeeper e{type:%s, server:%s, path:%s, state:%d-%s, err:%s}",
zkEvent.Type.String(), zkEvent.Server, zkEvent.Path, zkEvent.State, zookeeper.StateToString(zkEvent.State), zkEvent.Err,
)
if zkEvent.Type != zk.EventNodeChildrenChanged {
return true
}
Expand Down Expand Up @@ -169,7 +173,7 @@ func (asl *applicationServiceListener) handleEvent(children []string) {
MapTo: "opt.types",
},
}
if methods != nil && len(methods) != 0 {
if len(methods) != 0 {
for i := range methods {
api := registry.CreateAPIConfig(apiPattern, location, bkConfig, methods[i], mappingParams)
if err := asl.adapterListener.OnAddAPI(api); err != nil {
Expand Down Expand Up @@ -211,7 +215,7 @@ func (asl *applicationServiceListener) getUrls(path string) []*dubboCommon.URL {
return nil
}
instance.SetServiceMetadata(metadataInfo)
urls := make([]*dubboCommon.URL, 0)
urls := make([]*dubboCommon.URL, 0, len(metadataInfo.Services))
for _, service := range metadataInfo.Services {
urls = append(urls, instance.ToURLs(service)...)
}
Expand Down Expand Up @@ -247,8 +251,6 @@ func toZookeeperInstance(cris *curator_discovery.ServiceInstance) dr.ServiceInst

// getMethods return the methods of a service
func (asl *applicationServiceListener) getMethods(in string) ([]string, error) {
methods := []string{}

path := strings.Join([]string{methodsRootPath, in}, constant.PathSlash)
data, err := asl.client.GetContent(path)
if err != nil {
Expand All @@ -261,8 +263,9 @@ func (asl *applicationServiceListener) getMethods(in string) ([]string, error) {
return nil, err
}

for _, m := range sd.Methods {
methods = append(methods, m.Name)
methods := make([]string, len(sd.Methods))
for i := range sd.Methods {
methods[i] = sd.Methods[i].Name
}
return methods, nil
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/adapter/dubboregistry/remoting/zookeeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
// Options defines the client option.
type Options struct {
zkName string
ts *zk.TestCluster
ts *zk.TestCluster // nolint:unused
}

// Option defines the function to load the options
Expand Down Expand Up @@ -158,8 +158,10 @@ func (z *ZooKeeperClient) HandleZkEvent(s <-chan zk.Event) {
case <-z.exit:
return
case event = <-s:
logger.Infof("client{%s} get a zookeeper event{type:%s, server:%s, path:%s, state:%d-%s, err:%v}",
z.name, event.Type, event.Server, event.Path, event.State, StateToString(event.State), event.Err)
logger.Infof(
"client{%s} get a zookeeper event{type:%s, server:%s, path:%s, state:%d-%s, err:%v}",
z.name, event.Type, event.Server, event.Path, event.State, StateToString(event.State), event.Err,
)
switch event.State {
case zk.StateDisconnected:
logger.Warnf("zk{addr:%s} state is StateDisconnected, so close the zk client{name:%s}.", z.ZkAddrs, z.name)
Expand All @@ -170,8 +172,10 @@ func (z *ZooKeeperClient) HandleZkEvent(s <-chan zk.Event) {
z.eventRegistryLock.RLock()
for path, a := range z.eventRegistry {
if strings.HasPrefix(event.Path, path) {
logger.Infof("send event{state:zk.EventNodeDataChange, Path:%s} notify event to path{%s} related listener",
event.Path, path)
logger.Infof(
"send event{state:zk.EventNodeDataChange, Path:%s} notify event to path{%s} related listener",
event.Path, path,
)
for _, e := range a {
e <- event
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/cmd/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ var (
logFormat string

limitCpus string

// Currently default set to false, wait for up coming support
initFromRemote = false
)

var (
Expand Down Expand Up @@ -191,6 +188,7 @@ func initLogWithConfig(boot *model.Bootstrap) {
}
}

// nolint
// initApiConfig return value of the bool is for the judgment of whether is a api meta data error, a kind of silly (?)
func initApiConfig() (*model.Bootstrap, error) {
bootstrap := config.Load(configPath)
Expand Down
5 changes: 4 additions & 1 deletion pkg/common/grpc/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ func (gcm *GrpcConnectionManager) response(w stdHttp.ResponseWriter, res *stdHtt
if err != nil {
return err
}
w.Write(bytes)

if _, err = w.Write(bytes); err != nil {
return err
}

for k, vv := range res.Trailer {
k = stdHttp.TrailerPrefix + k
Expand Down
1 change: 1 addition & 0 deletions pkg/config/api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ func getExtractMethodRegexp() *regexp.Regexp {
return regexp.MustCompile(".+/resources/([^/]+)/method/[^/]+/?$")
}

// nolint
func getCheckRatelimitRegexp() *regexp.Regexp {
return regexp.MustCompile(".+/filter/ratelimit")
}
Expand Down
33 changes: 19 additions & 14 deletions pkg/config/config_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ var (
config *model.Bootstrap
configLoadFunc LoadFunc = LoadYAMLConfig

configCenterType map[string]interface{}
once sync.Once
once sync.Once
)

// LoadFunc ConfigLoadFunc parse a input(usually file path) into a pixiu config
Expand Down Expand Up @@ -182,7 +181,7 @@ func GetDiscoveryType(cfg *model.Bootstrap) (err error) {
}

type ConfigManager struct {
path string
path string // nolint:unused
localConfig *model.Bootstrap
remoteConfig *model.Bootstrap
load configcenter.Load
Expand Down Expand Up @@ -227,22 +226,28 @@ func (m *ConfigManager) loadRemoteBootConfigs() *model.Bootstrap {
bootstrap := m.localConfig

// load remote
once.Do(func() {
m.load = configcenter.NewConfigLoad(bootstrap)
})

configs, err := m.load.LoadConfigs(bootstrap, func(opt *configcenter.Options) {
opt.Remote = true
})
once.Do(
func() {
m.load = configcenter.NewConfigLoad(bootstrap)
},
)

configs, err := m.load.LoadConfigs(
bootstrap, func(opt *configcenter.Options) {
opt.Remote = true
},
)

if err != nil {
panic(err)
}

err = mergo.Merge(configs, bootstrap, func(c *mergo.Config) {
c.Overwrite = false
c.AppendSlice = false
})
err = mergo.Merge(
configs, bootstrap, func(c *mergo.Config) {
c.Overwrite = false
c.AppendSlice = false
},
)

if err != nil {
panic(err)
Expand Down
5 changes: 1 addition & 4 deletions pkg/config/config_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package config

import (
"encoding/json"
"fmt"
"log"
"os"
"testing"
Expand Down Expand Up @@ -140,11 +139,9 @@ func TestLoad(t *testing.T) {
conf := Load("conf_test.yaml")
assert.Equal(t, 1, len(conf.StaticResources.Listeners))
assert.Equal(t, 1, len(conf.StaticResources.Clusters))
Adapter(&b)
assert.Nil(t, Adapter(&b))
str1, _ := json.Marshal(conf.StaticResources)
str2, _ := json.Marshal(b.StaticResources)
fmt.Println(string(str1))
fmt.Println(string(str2))
assert.Equal(t, string(str1), string(str2))
}

Expand Down
1 change: 1 addition & 0 deletions pkg/filter/accesslog/access_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func buildAccessLogMsg(c *http.HttpContext, cost time.Duration) string {
return builder.String()
}

// nolint
// converter interface to byte array
func getBytes(key interface{}) ([]byte, error) {
var buf bytes.Buffer
Expand Down
18 changes: 8 additions & 10 deletions pkg/filter/http/grpcproxy/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ func (dr *Descriptor) initDescriptorSource(cfg *Config) *Descriptor {
}

func (dr *Descriptor) getServerDescriptorSourceCtx(refCtx context.Context, cfg *Config) (DescriptorSource, error) {
var cc *grpc.ClientConn
var err error
gconn := refCtx.Value(ct.ContextKey(GrpcClientConnKey))
switch t := gconn.(type) {
var (
err error
cc *grpc.ClientConn
)
switch t := refCtx.Value(ct.ContextKey(GrpcClientConnKey)).(type) {
case *grpc.ClientConn:
cc = gconn.(*grpc.ClientConn)
cc = t
case nil:
err = errors.New("the descriptor source not found!")
default:
Expand All @@ -117,19 +118,16 @@ func (dr *Descriptor) getServerDescriptorSourceCtx(refCtx context.Context, cfg *
return &serverSource{client: grpcreflect.NewClient(refCtx, reflectpb.NewServerReflectionClient(cc))}, err
}

// nolint
func (dr *Descriptor) getServerDescriptorSource(refCtx context.Context, cc *grpc.ClientConn) DescriptorSource {
return &serverSource{client: grpcreflect.NewClient(refCtx, reflectpb.NewServerReflectionClient(cc))}
}

func (dr *Descriptor) getFileDescriptorCompose(ctx context.Context, cfg *Config) (DescriptorSource, error) {

var err error

if dr.fileSource == nil {
dr.initFileDescriptorSource(cfg)
}

return dr.fileSource, err
return dr.fileSource, nil
}

func (dr *Descriptor) initFileDescriptorSource(cfg *Config) *Descriptor {
Expand Down
6 changes: 2 additions & 4 deletions pkg/listener/http/http_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func (ls *HttpListenerService) httpsListener() {
hl := createDefaultHttpWorker(ls)

// user customize http config
var hc *model.HttpConfig
hc = model.MapInStruct(ls.Config)
hc := model.MapInStruct(ls.Config)

mux := http.NewServeMux()
mux.HandleFunc("/", hl.ServeHTTP)
Expand Down Expand Up @@ -139,8 +138,7 @@ func (ls *HttpListenerService) httpListener() {
hl := createDefaultHttpWorker(ls)

// user customize http config
var hc *model.HttpConfig
hc = model.MapInStruct(ls.Config)
hc := model.MapInStruct(ls.Config)

mux := http.NewServeMux()
mux.HandleFunc("/", hl.ServeHTTP)
Expand Down
8 changes: 5 additions & 3 deletions pkg/router/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
// Node defines the single method of the router configured API
type Node struct {
fullPath string
filters []string
filters []string // nolint:unused
method *config.Method
headers map[string]string
}
Expand Down Expand Up @@ -134,8 +134,10 @@ func (rt *Route) PutAPI(api router.API) error {
_, _ = rt.tree.Put(key, rn)
return nil
}
return errors.Errorf("Method %s with address %s already exists in path %s",
api.Method.HTTPVerb, lowerCasePath, node.fullPath)
return errors.Errorf(
"Method %s with address %s already exists in path %s",
api.Method.HTTPVerb, lowerCasePath, node.fullPath,
)
}

// PutOrUpdateAPI puts or updates an api into the resource
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/cluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (cm *ClusterManager) PickEndpoint(clusterName string, policy model.LbPolicy
}

func (cm *ClusterManager) pickOneEndpoint(c *model.ClusterConfig, policy model.LbPolicy) *model.Endpoint {
if c.Endpoints == nil || len(c.Endpoints) == 0 {
if len(c.Endpoints) == 0 {
return nil
}

Expand Down

0 comments on commit e77c3aa

Please sign in to comment.