diff --git a/.golangci.yml b/.golangci.yml index 91f112787..33340b6fb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -281,7 +281,7 @@ linters-settings: govet: # Report about shadowed variables. # Default: false - check-shadowing: true + shadow: false # Settings per analyzer. settings: # Analyzer name, run `go tool vet help` to see all analyzers. diff --git a/bootstrap/server.go b/bootstrap/server.go index 117679ddb..f3f190632 100644 --- a/bootstrap/server.go +++ b/bootstrap/server.go @@ -76,7 +76,7 @@ func Start(configFilePath string) { fmt.Printf("[ERROR] config yaml marshal fail\n") return } - fmt.Printf(string(c)) + _, _ = fmt.Println(string(c)) // 初始化日志打印 err = log.Configure(cfg.Bootstrap.Logger) diff --git a/import-format.sh b/import-format.sh index 80033fe4c..9807c399e 100644 --- a/import-format.sh +++ b/import-format.sh @@ -17,7 +17,7 @@ # 格式化 go.mod go mod tidy -compat=1.17 -docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.55.2 golangci-lint run -v --timeout 30m +docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.61.0 golangci-lint run -v --timeout 30m # 处理 go imports 的格式化 rm -rf style_tool diff --git a/plugin/statis/logger/statis.go b/plugin/statis/logger/statis.go index 6a8121c09..8ce86b59a 100644 --- a/plugin/statis/logger/statis.go +++ b/plugin/statis/logger/statis.go @@ -97,7 +97,7 @@ func (s *StatisWorker) ReportConfigMetrics(metric ...metrics.ConfigMetrics) { // ReportDiscoverCall report discover service times func (s *StatisWorker) ReportDiscoverCall(metric metrics.ClientDiscoverMetric) { - discoverlog.Infof(metric.String()) + discoverlog.Info(metric.String()) } func (a *StatisWorker) metricsHandle(mt metrics.CallMetricType, start time.Time, diff --git a/store/boltdb/instance.go b/store/boltdb/instance.go index 0b61e055f..e97ecbeb2 100644 --- a/store/boltdb/instance.go +++ b/store/boltdb/instance.go @@ -19,7 +19,6 @@ package boltdb import ( "errors" - "fmt" "sort" "strconv" "strings" @@ -28,6 +27,7 @@ import ( "github.com/golang/protobuf/ptypes/wrappers" apiservice "github.com/polarismesh/specification/source/go/api/v1/service_manage" bolt "go.etcd.io/bbolt" + "go.uber.org/zap" "google.golang.org/protobuf/types/known/wrapperspb" "github.com/polarismesh/polaris/common/model" @@ -603,8 +603,7 @@ func (i *instanceStore) SetInstanceHealthStatus(instanceID string, flag int, rev return err } if len(instances) == 0 { - msg := fmt.Sprintf("cant not find instance in kv, %s", instanceID) - log.Errorf(msg) + log.Errorf("cant not find instance in kv, %s", instanceID) return nil } @@ -667,8 +666,7 @@ func (i *instanceStore) BatchSetInstanceIsolate(ids []interface{}, isolate int, return err } if len(instances) == 0 { - msg := fmt.Sprintf("cant not find instance in kv, %v", ids) - log.Errorf(msg) + log.Errorf("cant not find instance in kv, %v", ids) return nil } @@ -684,7 +682,7 @@ func (i *instanceStore) BatchSetInstanceIsolate(ids []interface{}, isolate int, instance.Mtime = &wrappers.StringValue{Value: commontime.Time2String(curr)} err = i.handler.UpdateValue(tblNameInstance, id, properties) if err != nil { - log.Errorf("[Store][boltdb] update instance in set instance isolate error, %v", err) + log.Error("[Store][boltdb] update instance in set instance isolate error", zap.Error(err)) return err } } diff --git a/store/mysql/admin.go b/store/mysql/admin.go index b3e775530..658c9d9cf 100644 --- a/store/mysql/admin.go +++ b/store/mysql/admin.go @@ -468,7 +468,7 @@ func (m *adminStore) BatchCleanDeletedInstances(timeout time.Duration, batchSize } cleanCheckStr := fmt.Sprintf("delete from health_check where id in (%s)", inSql) - if _, err := tx.Exec(cleanCheckStr, waitDelIds...); err != nil { + if _, err = tx.Exec(cleanCheckStr, waitDelIds...); err != nil { log.Errorf("[Store][database] batch clean soft deleted instances(%d), err: %s", batchSize, err.Error()) return store.Error(err) } @@ -487,7 +487,7 @@ func (m *adminStore) BatchCleanDeletedInstances(timeout time.Duration, batchSize return store.Error(err) } - if err := tx.Commit(); err != nil { + if err = tx.Commit(); err != nil { log.Errorf("[Store][database] batch clean soft deleted instances(%d) commit tx err: %s", batchSize, err.Error()) return err diff --git a/store/mysql/config_file.go b/store/mysql/config_file.go index bc8c35d3d..5854437e8 100644 --- a/store/mysql/config_file.go +++ b/store/mysql/config_file.go @@ -300,7 +300,7 @@ func (cf *configFileStore) QueryConfigFiles(filter map[string]string, offset, li err = cf.slave.processWithTransaction("batch-load-file-tags", func(tx *BaseTx) error { for i := range files { item := files[i] - if err := cf.loadFileTags(tx, item); err != nil { + if err = cf.loadFileTags(tx, item); err != nil { return err } } diff --git a/store/mysql/config_file_release.go b/store/mysql/config_file_release.go index 55e511f5c..f2fe05457 100644 --- a/store/mysql/config_file_release.go +++ b/store/mysql/config_file_release.go @@ -52,7 +52,7 @@ func (cfr *configFileReleaseStore) CreateConfigFileReleaseTx(tx store.Tx, data * } clean := "DELETE FROM config_file_release WHERE namespace = ? AND `group` = ? AND file_name = ? AND name = ? AND flag = 1" - if _, err := dbTx.Exec(clean, data.Namespace, data.Group, data.FileName, data.Name); err != nil { + if _, err = dbTx.Exec(clean, data.Namespace, data.Group, data.FileName, data.Name); err != nil { return store.Error(err) } diff --git a/store/mysql/group.go b/store/mysql/group.go index 938a10087..93df9d99a 100644 --- a/store/mysql/group.go +++ b/store/mysql/group.go @@ -128,14 +128,14 @@ func (u *groupStore) updateGroup(group *authcommon.ModifyUserGroup) error { // 更新用户-用户组关联数据 if len(group.AddUserIds) != 0 { - if err := u.addGroupRelation(tx, group.ID, group.AddUserIds); err != nil { + if err = u.addGroupRelation(tx, group.ID, group.AddUserIds); err != nil { log.Errorf("[Store][Group] add usergroup relation err: %s", err.Error()) return err } } if len(group.RemoveUserIds) != 0 { - if err := u.removeGroupRelation(tx, group.ID, group.RemoveUserIds); err != nil { + if err = u.removeGroupRelation(tx, group.ID, group.RemoveUserIds); err != nil { log.Errorf("[Store][Group] remove usergroup relation err: %s", err.Error()) return err } @@ -153,7 +153,7 @@ func (u *groupStore) updateGroup(group *authcommon.ModifyUserGroup) error { return err } - if err := tx.Commit(); err != nil { + if err = tx.Commit(); err != nil { log.Errorf("[Store][Group] update usergroup tx commit err: %s", err.Error()) return err } diff --git a/store/mysql/lane.go b/store/mysql/lane.go index 300e1e7e0..705f0b2ab 100644 --- a/store/mysql/lane.go +++ b/store/mysql/lane.go @@ -200,9 +200,9 @@ SELECT id, name, rule, description, revision, flag, UNIX_TIMESTAMP(ctime), UNIX_ for k, v := range filter { switch k { case "name": - if v, ok := utils.ParseWildName(v); ok { + if pv, ok := utils.ParseWildName(v); ok { conditions = append(conditions, "name = ?") - args = append(args, v) + args = append(args, pv) } else { conditions = append(conditions, "name LIKE ?") args = append(args, "%"+v+"%") diff --git a/store/mysql/strategy.go b/store/mysql/strategy.go index 38c7e9278..23c8e096d 100644 --- a/store/mysql/strategy.go +++ b/store/mysql/strategy.go @@ -128,30 +128,30 @@ func (s *strategyStore) updateStrategy(strategy *authcommon.ModifyStrategyDetail defer func() { _ = tx.Rollback() }() // 调整 principal 信息 - if err := s.addPolicyPrincipals(tx, strategy.ID, strategy.AddPrincipals); err != nil { + if err = s.addPolicyPrincipals(tx, strategy.ID, strategy.AddPrincipals); err != nil { log.Errorf("[Store][Strategy] add strategy principal err: %s", err.Error()) return err } - if err := s.deletePolicyPrincipals(tx, strategy.ID, strategy.RemovePrincipals); err != nil { + if err = s.deletePolicyPrincipals(tx, strategy.ID, strategy.RemovePrincipals); err != nil { log.Errorf("[Store][Strategy] remove strategy principal err: %s", err.Error()) return err } // 调整鉴权资源信息 - if err := s.addPolicyResources(tx, strategy.ID, strategy.AddResources); err != nil { + if err = s.addPolicyResources(tx, strategy.ID, strategy.AddResources); err != nil { log.Errorf("[Store][Strategy] add strategy resource err: %s", err.Error()) return err } - if err := s.deletePolicyResources(tx, strategy.ID, strategy.RemoveResources); err != nil { + if err = s.deletePolicyResources(tx, strategy.ID, strategy.RemoveResources); err != nil { log.Errorf("[Store][Strategy] remove strategy resource err: %s", err.Error()) return err } - if err := s.savePolicyFunctions(tx, strategy.ID, strategy.CalleeMethods); err != nil { + if err = s.savePolicyFunctions(tx, strategy.ID, strategy.CalleeMethods); err != nil { log.Error("[Store][Strategy] save auth_strategy functions", zap.Error(err)) return err } - if err := s.savePolicyConditions(tx, strategy.ID, strategy.Conditions); err != nil { + if err = s.savePolicyConditions(tx, strategy.ID, strategy.Conditions); err != nil { log.Error("[Store][Strategy] save auth_strategy conditions", zap.Error(err)) return err } @@ -163,7 +163,7 @@ func (s *strategyStore) updateStrategy(strategy *authcommon.ModifyStrategyDetail return err } - if err := tx.Commit(); err != nil { + if err = tx.Commit(); err != nil { log.Errorf("[Store][Strategy] update auth_strategy tx commit err: %s", err.Error()) return err } @@ -420,7 +420,7 @@ func (s *strategyStore) RemoveStrategyResources(resources []authcommon.StrategyR saveResSql = "DELETE FROM auth_strategy_resource WHERE res_id = ? AND res_type = ?" args = append(args, resource.ResID, resource.ResType) } - if _, err := tx.Exec(saveResSql, args...); err != nil { + if _, err = tx.Exec(saveResSql, args...); err != nil { return err } // 主要是为了能够触发 StrategyCache 的刷新逻辑 @@ -430,7 +430,7 @@ func (s *strategyStore) RemoveStrategyResources(resources []authcommon.StrategyR } } - if err := tx.Commit(); err != nil { + if err = tx.Commit(); err != nil { log.Errorf("[Store][Strategy] add auth_strategy tx commit err: %s", err.Error()) return err } diff --git a/test/data/bolt-data.yaml b/test/data/bolt-data.yaml index 3092c1ad8..2c7827204 100644 --- a/test/data/bolt-data.yaml +++ b/test/data/bolt-data.yaml @@ -1,3 +1,18 @@ +# Tencent is pleased to support the open source community by making Polaris available. +# +# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. +# +# Licensed under the BSD 3-Clause License (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://opensource.org/licenses/BSD-3-Clause +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + users: - name: polaris token: nu/0WRA4EqSR1FagrjRj0fZwPXuGlMpX+zCuWu4uMqy8xr1vRjisSbA25aAC3mtU8MeeRsKhQiDAynUR09I=