From 33be96fede3c70b37cf87d3340f9abfa79f0584f Mon Sep 17 00:00:00 2001 From: xiaoming <357447923@qq.com> Date: Wed, 16 Aug 2023 23:06:30 +0800 Subject: [PATCH] [CI] add basic static check, compile, test Signed-off-by: xiaoming <357447923@qq.com> [fix]playbook: fix format related variables position Signed-off-by: sjf [fix] add support for recognizing kernel versions like "3.15.0_.*" Signed-off-by: jyf111 support enable etcd auth Signed-off-by: wanghai01 Feature: podman can be an alternative container engine Signed-off-by: caoxianfei1 bugfix: docker ps specify both --format and --quiet will warning since v24.0.0. WARNING: Ignoring custom format, because both --format and --quiet are set. Signed-off-by: caoxianfei1 change replicas to instances Signed-off-by: tec-rubbish maker change topology variable change service_replicas_sequence and format_replicas_sequence to service_instances_sequence and format_instances_sequence Signed-off-by: tec-rubbish maker fix the worng instances Signed-off-by: tec-rubbish maker mistake Signed-off-by: tec-rubbish maker Update cli/command/status.go Signed-off-by: Wine93 [fix] older versions of the ss command do not have the --no-header option solution: execute the ss command in a temporary container to precheck for ports in use instead Signed-off-by: jyf111 Signed-off-by: xiaoming <357447923@qq.com> --- .github/workflows/CodeQL.yml | 54 +++++++++++++++++++ .github/workflows/go.yml | 22 ++++++-- .golangci.yml | 38 +++++++++++++ Makefile | 11 +++- cli/cli/cli.go | 5 +- cli/command/clean.go | 2 +- cli/command/client/map.go | 1 - cli/command/cluster/import.go | 5 +- cli/command/completion.go | 2 +- cli/command/deploy.go | 4 +- cli/command/exec.go | 1 - cli/command/status.go | 2 +- http/manager/manager.go | 2 +- internal/configure/client.go | 9 ---- internal/configure/hosts/hosts.go | 2 +- internal/configure/pool.go | 12 ++--- internal/configure/topology/dc.go | 8 +-- internal/configure/topology/dc_get.go | 10 ++-- internal/configure/topology/variables.go | 11 ++-- internal/errno/errno.go | 2 +- internal/playbook/configs.go | 36 ++++++------- internal/playbook/tasks/tasks.go | 6 +-- internal/task/scripts/enable_etcd_auth.go | 4 +- internal/task/scripts/monitor.go | 2 +- internal/task/task/bs/delete_target.go | 2 +- internal/task/task/bs/format_stop.go | 2 +- internal/task/task/bs/list_targets.go | 2 +- internal/task/task/bs/start_nebd.go | 2 +- internal/task/task/bs/start_tgtd.go | 2 +- internal/task/task/checker/common.go | 10 ++-- internal/task/task/checker/kernel.go | 2 +- internal/task/task/checker/service.go | 2 +- internal/task/task/checker/ssh.go | 2 +- internal/task/task/checker/topology.go | 3 +- internal/task/task/common/clean_service.go | 2 +- internal/task/task/common/collect_report.go | 22 -------- internal/task/task/common/create_pool.go | 8 +-- internal/task/task/common/restart_service.go | 12 ----- internal/task/task/common/sync_config.go | 2 +- internal/task/task/monitor/clean_service.go | 2 +- internal/task/task/playground/init.go | 6 +-- internal/task/task/task.go | 1 - internal/task/task/website/clean_service.go | 4 +- internal/task/task/website/restart_service.go | 2 +- internal/task/task/website/start_service.go | 2 +- internal/task/task/website/stop_service.go | 2 +- internal/task/task/website/sync_config.go | 2 +- internal/task/tasks/tasks.go | 6 +-- internal/tasks/tasks.go | 4 +- internal/tui/service/status.go | 2 +- internal/utils/cobra.go | 3 +- internal/utils/common.go | 2 +- internal/utils/map.go | 4 +- pkg/log/glg/log.go | 9 ++-- pkg/log/log.go | 14 ++--- pkg/log/zaplog/log.go | 14 ++--- pkg/module/ssh.go | 2 +- pkg/variable/variables.go | 7 ++- 58 files changed, 236 insertions(+), 178 deletions(-) create mode 100644 .github/workflows/CodeQL.yml create mode 100644 .golangci.yml diff --git a/.github/workflows/CodeQL.yml b/.github/workflows/CodeQL.yml new file mode 100644 index 000000000..39b438f6f --- /dev/null +++ b/.github/workflows/CodeQL.yml @@ -0,0 +1,54 @@ +name: "CodeQL" + +on: + push: + branches: [ "master","develop" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master","develop" ] + schedule: + - cron: '0 17 * * 5' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + # timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 42c520809..4218c0e6e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,7 +7,23 @@ on: branches: [ $default-branch, "develop" ] jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Setup go + uses: actions/setup-go@v3 + with: + go-version: '1.19' + - name: Checkout repository + uses: actions/checkout@v3 + - name: Setup golangci-lint + uses: golangci/golangci-lint-action@v3.4.0 + with: + version: v1.52.2 + args: --verbose + test: + needs: lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -21,7 +37,7 @@ jobs: run: make test build: - needs: test + needs: lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -29,7 +45,5 @@ jobs: uses: actions/setup-go@v3 with: go-version: 1.19 - - name: Set dependencies - run: sudo apt update && sudo apt install musl-tools - name: Build - run: make build + run: go build -v ./... diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..9a8b315a9 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,38 @@ +run: + timeout: 5m +linters: + enable: + # Simple linter to check that your code does not contain non-ASCII identifiers. + - asciicheck + # Go linter that checks if package imports are in a list of acceptable packages. + - depguard + # Checks for pointers to enclosing loop variables. + - exportloopref + # Gofmt checks whether code was gofmt-ed + - gofmt + # Inspects source code for security problems. + - gosec + # Finds naked returns in functions greater than a specified function length. + - nakedret + # Reports ill-formed or insufficient nolint directives. + - nolintlint + # Checks for dangerous unicode character sequences. + - bidichk + disable: + # ignore errcheck + - errcheck +linters-settings: + gosec: + # Available rules: https://github.com/securego/gosec#available-rules + excludes: + - G101 # Look for hard coded credentials + - G204 # Audit use of command execution + - G401 # Detect the usage of DES, RC4, MD5 or SHA1 + - G403 # Ensure minimum RSA key length of 2048 bits + - G404 # Insecure random number source (rand) + - G501 # Import blocklist: crypto/md5 + - G502 # Import blocklist: crypto/des + - G503 # Import blocklist: crypto/rc4 + - G504 # Import blocklist: net/http/cgi + - G505 # Import blocklist: crypto/sha1 + - G601 # Implicit memory aliasing of items from a range statement diff --git a/Makefile b/Makefile index 4e92ad68c..471b0fcb9 100644 --- a/Makefile +++ b/Makefile @@ -56,14 +56,16 @@ SERVER_PACKAGES := $(PWD)/cmd/service/main.go # tar VERSION := "unknown" -build: +build: fmt vet $(GOENV) $(GO) build -o $(OUTPUT) $(BUILD_FLAGS) $(PACKAGES) $(GOENV) $(GO) build -o $(SERVER_OUTPUT) $(BUILD_FLAGS) $(SERVER_PACKAGES) -debug: + +debug: fmt vet $(GOENV) $(GO) build -o $(OUTPUT) $(DEBUG_FLAGS) $(PACKAGES) $(GOENV) $(GO) build -o $(SERVER_OUTPUT) $(DEBUG_FLAGS) $(SERVER_PACKAGES) + test: $(GO_TEST) $(TEST_FLAGS) ./... @@ -74,3 +76,8 @@ lint: go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION) $(GOBIN_GOLANGCILINT) run -v +fmt: + go fmt ./... + +vet: + go vet ./... diff --git a/cli/cli/cli.go b/cli/cli/cli.go index f7b113803..8d3e538de 100644 --- a/cli/cli/cli.go +++ b/cli/cli/cli.go @@ -248,7 +248,7 @@ func (curveadm *CurveAdm) detectVersion() { } func (curveadm *CurveAdm) Upgrade() (bool, error) { - if curveadm.config.GetAutoUpgrade() == false { + if !curveadm.config.GetAutoUpgrade() { return false, nil } @@ -551,8 +551,7 @@ func (curveadm *CurveAdm) PostAudit(id int64, ec error) { return } - auditLog := auditLogs[0] - status := auditLog.Status + var status int errorCode := 0 if ec == nil { status = comm.AUDIT_STATUS_SUCCESS diff --git a/cli/command/clean.go b/cli/command/clean.go index 3a5d138b4..27f703768 100644 --- a/cli/command/clean.go +++ b/cli/command/clean.go @@ -121,7 +121,7 @@ func genCleanPlaybook(curveadm *cli.CurveAdm, Configs: dcs, Options: map[string]interface{}{ comm.KEY_CLEAN_ITEMS: options.only, - comm.KEY_CLEAN_BY_RECYCLE: options.withoutRecycle == false, + comm.KEY_CLEAN_BY_RECYCLE: !options.withoutRecycle, }, }) } diff --git a/cli/command/client/map.go b/cli/command/client/map.go index 5255c7a14..9cb0b3c53 100644 --- a/cli/command/client/map.go +++ b/cli/command/client/map.go @@ -27,7 +27,6 @@ import ( "strings" "github.com/dustin/go-humanize" - "github.com/fatih/color" "github.com/opencurve/curveadm/cli/cli" comm "github.com/opencurve/curveadm/internal/common" diff --git a/cli/command/cluster/import.go b/cli/command/cluster/import.go index 2ef49de17..b9f916b88 100644 --- a/cli/command/cluster/import.go +++ b/cli/command/cluster/import.go @@ -138,10 +138,8 @@ func readDatabase(filename string) (storage.Cluster, []storage.Service, error) { switch id { case CLUSTER_DESCRIPTION: cluster.Description = value - break case CLUSTER_TOPOLOGY: cluster.Topology = value - break case SERVICE: items := strings.Split(value, " ") if len(items) != 2 { @@ -166,7 +164,8 @@ func importCluster(storage *storage.Storage, name, dbfile string) error { } // insert cluster - if storage.InsertCluster(name, cluster.Description, cluster.Topology); err != nil { + err = storage.InsertCluster(name, cluster.Description, cluster.Topology) + if err != nil { return err } diff --git a/cli/command/completion.go b/cli/command/completion.go index d2d601849..d3a50a2cf 100644 --- a/cli/command/completion.go +++ b/cli/command/completion.go @@ -77,7 +77,7 @@ PowerShell: `, "curveadm"), DisableFlagsInUseLine: true, ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, - Args: cobra.ExactValidArgs(1), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { switch args[0] { case "bash": diff --git a/cli/command/deploy.go b/cli/command/deploy.go index 6977261c8..e3a336f2f 100644 --- a/cli/command/deploy.go +++ b/cli/command/deploy.go @@ -229,9 +229,9 @@ func genDeployPlaybook(curveadm *cli.CurveAdm, role := DEPLOY_FILTER_ROLE[step] config = curveadm.FilterDeployConfigByRole(config, role) } - n := len(config) + if DEPLOY_LIMIT_SERVICE[step] > 0 { - n = DEPLOY_LIMIT_SERVICE[step] + n := DEPLOY_LIMIT_SERVICE[step] config = config[:n] } diff --git a/cli/command/exec.go b/cli/command/exec.go index 7b62c037a..3c3c49f30 100644 --- a/cli/command/exec.go +++ b/cli/command/exec.go @@ -48,7 +48,6 @@ func NewExecCommand(curveadm *cli.CurveAdm) *cobra.Command { PreRunE: func(cmd *cobra.Command, args []string) error { options.id = args[0] options.cmd = strings.Join(args[1:], " ") - args = args[:1] return curveadm.CheckId(options.id) }, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cli/command/status.go b/cli/command/status.go index 98491a9f5..041f52768 100644 --- a/cli/command/status.go +++ b/cli/command/status.go @@ -73,7 +73,7 @@ func NewStatusCommand(curveadm *cli.CurveAdm) *cobra.Command { flags.StringVar(&options.role, "role", "*", "Specify service role") flags.StringVar(&options.host, "host", "*", "Specify service host") flags.BoolVarP(&options.verbose, "verbose", "v", false, "Verbose output for status") -flags.BoolVarP(&options.showInstances, "show-instances", "s", false, "Display service instances") + flags.BoolVarP(&options.showInstances, "show-instances", "s", false, "Display service instances") return cmd } diff --git a/http/manager/manager.go b/http/manager/manager.go index b6099b00a..e919830f2 100644 --- a/http/manager/manager.go +++ b/http/manager/manager.go @@ -308,7 +308,7 @@ func GetClusterServicesAddr(r *pigeon.Request, ctx *Context) bool { pigeon.Field("error", err)) return core.ExitSuccessWithData(r, servicesAddr) } - } + } servicesAddr.ClusterId = adm.ClusterId() servicesAddr.Addrs = getServicesAddrFromConf(dcs, mcs) return core.ExitSuccessWithData(r, servicesAddr) diff --git a/internal/configure/client.go b/internal/configure/client.go index 607cb7638..1adb27232 100644 --- a/internal/configure/client.go +++ b/internal/configure/client.go @@ -83,7 +83,6 @@ type ( config map[string]interface{} serviceConfig map[string]string variables *variable.Variables - data string // configure file content } ) @@ -167,14 +166,6 @@ func (cc *ClientConfig) getString(key string) string { return v.(string) } -func (cc *ClientConfig) getBool(key string) bool { - v := cc.config[strings.ToLower(key)] - if v == nil { - return false - } - return v.(bool) -} - func (cc *ClientConfig) GetKind() string { return cc.getString(KEY_KIND) } func (cc *ClientConfig) GetDataDir() string { return cc.getString(KEY_DATA_DIR) } func (cc *ClientConfig) GetLogDir() string { return cc.getString(KEY_LOG_DIR) } diff --git a/internal/configure/hosts/hosts.go b/internal/configure/hosts/hosts.go index c8fa86011..96f303368 100644 --- a/internal/configure/hosts/hosts.go +++ b/internal/configure/hosts/hosts.go @@ -158,7 +158,7 @@ func (hc *HostConfig) Build() error { F("hosts[%d].private_key_file = %s", hc.sequence, privateKeyFile) } - if hc.GetForwardAgent() == false { + if !hc.GetForwardAgent() { if !utils.PathExist(privateKeyFile) { return errno.ERR_PRIVATE_KEY_FILE_NOT_EXIST. F("%s: no such file", privateKeyFile) diff --git a/internal/configure/pool.go b/internal/configure/pool.go index 41c35a673..b0e37c5c4 100644 --- a/internal/configure/pool.go +++ b/internal/configure/pool.go @@ -241,9 +241,7 @@ func ScaleOutClusterPool(old *CurveClusterTopo, dcs []*topology.DeployConfig, po npools := old.NPools topo := generateClusterPool(dcs, fmt.Sprintf("pool%d", npools+1), poolset, diskType) if dcs[0].GetKind() == KIND_CURVEBS { - for _, pool := range topo.LogicalPools { - old.LogicalPools = append(old.LogicalPools, pool) - } + old.LogicalPools = append(old.LogicalPools, topo.LogicalPools...) for _, newPst := range topo.Poolsets { isExist := false for _, oldPst := range old.Poolsets { @@ -256,13 +254,9 @@ func ScaleOutClusterPool(old *CurveClusterTopo, dcs []*topology.DeployConfig, po } } } else { - for _, pool := range topo.Pools { - old.Pools = append(old.Pools, pool) - } - } - for _, server := range topo.Servers { - old.Servers = append(old.Servers, server) + old.Pools = append(old.Pools, topo.Pools...) } + old.Servers = append(old.Servers, topo.Servers...) old.NPools = old.NPools + 1 } diff --git a/internal/configure/topology/dc.go b/internal/configure/topology/dc.go index b57ed770f..182a4a5eb 100644 --- a/internal/configure/topology/dc.go +++ b/internal/configure/topology/dc.go @@ -86,7 +86,7 @@ func formatName(name string, hostSequence int) string { func newVariables(m map[string]interface{}) (*variable.Variables, error) { vars := variable.NewVariables() - if m == nil || len(m) == 0 { + if len(m) == 0 { return vars, nil } @@ -182,8 +182,8 @@ func (dc *DeployConfig) renderVariables() error { } dc.config[k] = realv build.DEBUG(build.DEBUG_TOPOLOGY, - build.Field{k, v}, - build.Field{k, realv}) + build.Field{Key: k, Value: v}, + build.Field{Key: k, Value: realv}) } return nil } @@ -192,7 +192,7 @@ func (dc *DeployConfig) convert() error { // init service config for k, v := range dc.config { item := itemset.get(k) - if item == nil || item.exclude == false { + if item == nil || !item.exclude { dc.serviceConfig[k] = v.(string) } } diff --git a/internal/configure/topology/dc_get.go b/internal/configure/topology/dc_get.go index cf02f07d2..aeefa430f 100644 --- a/internal/configure/topology/dc_get.go +++ b/internal/configure/topology/dc_get.go @@ -65,11 +65,11 @@ var ( DefaultCurveFSDeployConfig = &DeployConfig{kind: KIND_CURVEFS} ServiceConfigs = map[string][]string{ - ROLE_ETCD: []string{"etcd.conf"}, - ROLE_MDS: []string{"mds.conf"}, - ROLE_CHUNKSERVER: []string{"chunkserver.conf", "cs_client.conf", "s3.conf"}, - ROLE_SNAPSHOTCLONE: []string{"snapshotclone.conf", "snap_client.conf", "s3.conf", "nginx.conf"}, - ROLE_METASERVER: []string{"metaserver.conf"}, + ROLE_ETCD: {"etcd.conf"}, + ROLE_MDS: {"mds.conf"}, + ROLE_CHUNKSERVER: {"chunkserver.conf", "cs_client.conf", "s3.conf"}, + ROLE_SNAPSHOTCLONE: {"snapshotclone.conf", "snap_client.conf", "s3.conf", "nginx.conf"}, + ROLE_METASERVER: {"metaserver.conf"}, } ) diff --git a/internal/configure/topology/variables.go b/internal/configure/topology/variables.go index 02cb4bb65..e1ec6dadf 100644 --- a/internal/configure/topology/variables.go +++ b/internal/configure/topology/variables.go @@ -43,11 +43,10 @@ const ( ) type Var struct { - name string - kind []string // kind limit for register variable - role []string // role limit for register variable - lookup bool // whether need to lookup host - resolved bool + name string + kind []string // kind limit for register variable + role []string // role limit for register variable + lookup bool // whether need to lookup host } /* @@ -141,7 +140,7 @@ func skip(dc *DeployConfig, v Var) bool { func addVariables(dcs []*DeployConfig, idx int, vars []Var) error { dc := dcs[idx] for _, v := range vars { - if skip(dc, v) == true { + if skip(dc, v) { continue } diff --git a/internal/errno/errno.go b/internal/errno/errno.go index f3d0c1e51..fd40bbc00 100644 --- a/internal/errno/errno.go +++ b/internal/errno/errno.go @@ -55,7 +55,7 @@ func Init(logpath string) { func List() error { count := map[int]int{} for _, e := range elist { - fmt.Printf(color.GreenString("%06d ", e.code)) + fmt.Print(color.GreenString("%06d ", e.code)) fmt.Println(color.YellowString("%s", e.description)) count[e.code]++ } diff --git a/internal/playbook/configs.go b/internal/playbook/configs.go index 4d03829cb..80c88b85b 100644 --- a/internal/playbook/configs.go +++ b/internal/playbook/configs.go @@ -133,72 +133,72 @@ func NewSmartConfig(configs interface{}) (*SmartConfig, error) { anys: []interface{}{}, } build.DEBUG(build.DEBUG_SMART_CONFIGS, - build.Field{"len", c.len}, - build.Field{"type", c.ctype}) + build.Field{Key: "len", Value: c.len}, + build.Field{Key: "type", Value: c.ctype}) - switch configs.(type) { + switch configs := configs.(type) { // multi-configs case []*hosts.HostConfig: c.ctype = TYPE_CONFIG_HOST - c.hcs = configs.([]*hosts.HostConfig) + c.hcs = configs c.len = len(c.hcs) case []*configure.FormatConfig: c.ctype = TYPE_CONFIG_FORMAT - c.fcs = configs.([]*configure.FormatConfig) + c.fcs = configs c.len = len(c.fcs) case []*topology.DeployConfig: c.ctype = TYPE_CONFIG_DEPLOY - c.dcs = configs.([]*topology.DeployConfig) + c.dcs = configs c.len = len(c.dcs) case []*configure.ClientConfig: c.ctype = TYPE_CONFIG_CLIENT - c.ccs = configs.([]*configure.ClientConfig) + c.ccs = configs c.len = len(c.ccs) case []*configure.PlaygroundConfig: c.ctype = TYPE_CONFIG_PLAYGROUND - c.pgcs = configs.([]*configure.PlaygroundConfig) + c.pgcs = configs c.len = len(c.pgcs) case []*configure.MonitorConfig: c.ctype = TYPE_CONFIG_MONITOR - c.mcs = configs.([]*configure.MonitorConfig) + c.mcs = configs c.len = len(c.mcs) case []*configure.WebsiteConfig: c.ctype = TYPE_CONFIG_WEBSITE - c.wcs = configs.([]*configure.WebsiteConfig) + c.wcs = configs c.len = len(c.wcs) case []interface{}: c.ctype = TYPE_CONFIG_ANY - c.anys = configs.([]interface{}) + c.anys = configs c.len = len(c.anys) // single-config case *hosts.HostConfig: c.ctype = TYPE_CONFIG_HOST - c.hcs = append(c.hcs, configs.(*hosts.HostConfig)) + c.hcs = append(c.hcs, configs) c.len = 1 case *configure.FormatConfig: c.ctype = TYPE_CONFIG_FORMAT - c.fcs = append(c.fcs, configs.(*configure.FormatConfig)) + c.fcs = append(c.fcs, configs) c.len = 1 case *topology.DeployConfig: c.ctype = TYPE_CONFIG_DEPLOY - c.dcs = append(c.dcs, configs.(*topology.DeployConfig)) + c.dcs = append(c.dcs, configs) c.len = 1 case *configure.ClientConfig: c.ctype = TYPE_CONFIG_CLIENT - c.ccs = append(c.ccs, configs.(*configure.ClientConfig)) + c.ccs = append(c.ccs, configs) c.len = 1 case *configure.PlaygroundConfig: c.ctype = TYPE_CONFIG_PLAYGROUND - c.pgcs = append(c.pgcs, configs.(*configure.PlaygroundConfig)) + c.pgcs = append(c.pgcs, configs) c.len = 1 case *configure.MonitorConfig: c.ctype = TYPE_CONFIG_MONITOR - c.mcs = append(c.mcs, configs.(*configure.MonitorConfig)) + c.mcs = append(c.mcs, configs) c.len = 1 case *configure.WebsiteConfig: c.ctype = TYPE_CONFIG_WEBSITE - c.wcs = append(c.wcs, configs.(*configure.WebsiteConfig)) + c.wcs = append(c.wcs, configs) c.len = 1 case nil: c.ctype = TYPE_CONFIG_NULL diff --git a/internal/playbook/tasks/tasks.go b/internal/playbook/tasks/tasks.go index a680a68dc..2e778df14 100644 --- a/internal/playbook/tasks/tasks.go +++ b/internal/playbook/tasks/tasks.go @@ -45,7 +45,7 @@ type ( Tasks struct { tasks []*task.Task monitor *monitor - wg sync.WaitGroup + wg *sync.WaitGroup progress *mpb.Progress mainBar *mpb.Bar subBar map[string]*mpb.Bar @@ -58,7 +58,7 @@ func NewTasks() *Tasks { return &Tasks{ tasks: []*task.Task{}, monitor: newMonitor(), - wg: wg, + wg: &wg, progress: mpb.New(mpb.WithWaitGroup(&wg)), mainBar: nil, subBar: map[string]*mpb.Bar{}, @@ -212,7 +212,7 @@ func (ts *Tasks) Execute(option ExecOptions) error { // execute task by concurrency for _, t := range ts.tasks { - if ts.monitor.error() != nil && option.SkipError == false { + if ts.monitor.error() != nil && !option.SkipError { break } diff --git a/internal/task/scripts/enable_etcd_auth.go b/internal/task/scripts/enable_etcd_auth.go index a18ff157c..33e14102e 100644 --- a/internal/task/scripts/enable_etcd_auth.go +++ b/internal/task/scripts/enable_etcd_auth.go @@ -12,13 +12,13 @@ * 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. -*/ + */ /* * Project: Curveadm * Created Date: 2023-08-02 * Author: wanghai (SeanHai) -*/ + */ package scripts diff --git a/internal/task/scripts/monitor.go b/internal/task/scripts/monitor.go index cf6f25302..824513a76 100644 --- a/internal/task/scripts/monitor.go +++ b/internal/task/scripts/monitor.go @@ -51,4 +51,4 @@ datasources: is_default: true version: 1 editable: true -` \ No newline at end of file +` diff --git a/internal/task/task/bs/delete_target.go b/internal/task/task/bs/delete_target.go index c976186d0..7cb454fb0 100644 --- a/internal/task/task/bs/delete_target.go +++ b/internal/task/task/bs/delete_target.go @@ -76,7 +76,7 @@ func NewDeleteTargetTask(curveadm *cli.CurveAdm, cc *client.ClientConfig) (*task }) t.AddStep(&step.ContainerExec{ ContainerId: &containerId, - Command: fmt.Sprintf("tgtadm --lld iscsi --mode target --op show"), + Command: "tgtadm --lld iscsi --mode target --op show", Out: &output, ExecOptions: curveadm.ExecOptions(), }) diff --git a/internal/task/task/bs/format_stop.go b/internal/task/task/bs/format_stop.go index 5ed06735e..aff2902a4 100644 --- a/internal/task/task/bs/format_stop.go +++ b/internal/task/task/bs/format_stop.go @@ -34,7 +34,7 @@ import ( func skipStopFormat(containerId *string) step.LambdaType { return func(ctx *context.Context) error { - if len(*containerId) < 0 { + if len(*containerId) == 0 { return task.ERR_SKIP_TASK } return nil diff --git a/internal/task/task/bs/list_targets.go b/internal/task/task/bs/list_targets.go index 93334a446..f7543ca8c 100644 --- a/internal/task/task/bs/list_targets.go +++ b/internal/task/task/bs/list_targets.go @@ -129,7 +129,7 @@ func NewListTargetsTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task, erro }) t.AddStep(&step.ContainerExec{ ContainerId: &containerId, - Command: fmt.Sprintf("tgtadm --lld iscsi --mode target --op show"), + Command: "tgtadm --lld iscsi --mode target --op show", Out: &output, ExecOptions: curveadm.ExecOptions(), }) diff --git a/internal/task/task/bs/start_nebd.go b/internal/task/task/bs/start_nebd.go index f3e39495f..d7fdcaccd 100644 --- a/internal/task/task/bs/start_nebd.go +++ b/internal/task/task/bs/start_nebd.go @@ -187,7 +187,7 @@ func NewStartNEBDServiceTask(curveadm *cli.CurveAdm, cc *configure.ClientConfig) AddHost: []string{host2addr}, Envs: []string{"LD_PRELOAD=/usr/local/lib/libjemalloc.so"}, Hostname: hostname, - Command: fmt.Sprintf("--role nebd"), + Command: "--role nebd", Name: containerName, Pid: "host", Privileged: true, diff --git a/internal/task/task/bs/start_tgtd.go b/internal/task/task/bs/start_tgtd.go index a19aa02e1..ef4358e35 100644 --- a/internal/task/task/bs/start_tgtd.go +++ b/internal/task/task/bs/start_tgtd.go @@ -93,7 +93,7 @@ func NewStartTargetDaemonTask(curveadm *cli.CurveAdm, cc *configure.ClientConfig AddHost: []string{host2addr}, Envs: []string{"LD_PRELOAD=/usr/local/lib/libjemalloc.so"}, Hostname: hostname, - Command: fmt.Sprintf("--role nebd"), + Command: "--role nebd", Name: containerName, Pid: "host", Privileged: true, diff --git a/internal/task/task/checker/common.go b/internal/task/task/checker/common.go index e9830da80..c97c379b3 100644 --- a/internal/task/task/checker/common.go +++ b/internal/task/task/checker/common.go @@ -55,11 +55,11 @@ const ( var ( CONNECT = map[string][]string{ - ROLE_ETCD: []string{ROLE_ETCD}, - ROLE_MDS: []string{ROLE_MDS, ROLE_ETCD}, - ROLE_CHUNKSERVER: []string{ROLE_CHUNKSERVER, ROLE_MDS}, - ROLE_SNAPSHOTCLONE: []string{ROLE_SNAPSHOTCLONE}, - ROLE_METASERVER: []string{ROLE_METASERVER, ROLE_MDS}, + ROLE_ETCD: {ROLE_ETCD}, + ROLE_MDS: {ROLE_MDS, ROLE_ETCD}, + ROLE_CHUNKSERVER: {ROLE_CHUNKSERVER, ROLE_MDS}, + ROLE_SNAPSHOTCLONE: {ROLE_SNAPSHOTCLONE}, + ROLE_METASERVER: {ROLE_METASERVER, ROLE_MDS}, } ) diff --git a/internal/task/task/checker/kernel.go b/internal/task/task/checker/kernel.go index 3db2ed1d9..7a3c4b36e 100644 --- a/internal/task/task/checker/kernel.go +++ b/internal/task/task/checker/kernel.go @@ -84,7 +84,7 @@ func checkKernelVersion(out *string, dc *topology.DeployConfig) step.LambdaType func checkKernelModule(name string, success *bool, out *string) step.LambdaType { return func(ctx *context.Context) error { - if *success == true { + if *success { return nil } diff --git a/internal/task/task/checker/service.go b/internal/task/task/checker/service.go index a4c642765..4a9a3af35 100644 --- a/internal/task/task/checker/service.go +++ b/internal/task/task/checker/service.go @@ -64,7 +64,7 @@ type ( func (s *step2CheckChunkfilePool) Execute(ctx *context.Context) error { dc := s.dc dataDir := dc.GetDataDir() - if dc.GetEnableChunkfilePool() == false { + if !dc.GetEnableChunkfilePool() { return nil } else if len(dataDir) == 0 { return errno.ERR_CHUNKFILE_POOL_NOT_EXIST diff --git a/internal/task/task/checker/ssh.go b/internal/task/task/checker/ssh.go index 9d0e893bd..f5e3a4528 100644 --- a/internal/task/task/checker/ssh.go +++ b/internal/task/task/checker/ssh.go @@ -51,7 +51,7 @@ func doNothing() step.LambdaType { func checkHost(hc *hosts.HostConfig) step.LambdaType { return func(ctx *context.Context) error { privateKeyFile := hc.GetPrivateKeyFile() - if hc.GetForwardAgent() == false { + if !hc.GetForwardAgent() { if !utils.PathExist(privateKeyFile) { return errno.ERR_PRIVATE_KEY_FILE_NOT_EXIST. F("%s: no such file", privateKeyFile) diff --git a/internal/task/task/checker/topology.go b/internal/task/task/checker/topology.go index 9b6c5185e..4e4a23875 100644 --- a/internal/task/task/checker/topology.go +++ b/internal/task/task/checker/topology.go @@ -55,8 +55,7 @@ type ( // check whether directory path is absolute path step2CheckDirectoryPath struct { - sequence int - dc *topology.DeployConfig + dc *topology.DeployConfig } // check whether the data directory is duplicate diff --git a/internal/task/task/common/clean_service.go b/internal/task/task/common/clean_service.go index 870302f65..d20513929 100644 --- a/internal/task/task/common/clean_service.go +++ b/internal/task/task/common/clean_service.go @@ -205,7 +205,7 @@ func NewCleanServiceTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*ta Files: files, ExecOptions: curveadm.ExecOptions(), }) - if clean[comm.CLEAN_ITEM_CONTAINER] == true { + if clean[comm.CLEAN_ITEM_CONTAINER] { t.AddStep(&Step2CleanContainer{ ServiceId: serviceId, ContainerId: containerId, diff --git a/internal/task/task/common/collect_report.go b/internal/task/task/common/collect_report.go index 19bd9b447..67fb4a336 100644 --- a/internal/task/task/common/collect_report.go +++ b/internal/task/task/common/collect_report.go @@ -23,14 +23,10 @@ package common import ( - "fmt" - "strings" - "github.com/opencurve/curveadm/cli/cli" "github.com/opencurve/curveadm/internal/configure/topology" "github.com/opencurve/curveadm/internal/errno" "github.com/opencurve/curveadm/internal/task/context" - "github.com/opencurve/curveadm/internal/task/step" "github.com/opencurve/curveadm/internal/task/task" "github.com/opencurve/curveadm/internal/utils" ) @@ -43,24 +39,6 @@ type ( } ) -func appendOut(command string, success *bool, out *string, outs *[]string) step.LambdaType { - return func(ctx *context.Context) error { - if !*success { - *outs = append(*outs, fmt.Sprintf("<%s>: failed", command)) - } else { - *outs = append(*outs, *out) - } - return nil - } -} - -func convert2Content(outs *[]string, content *string) step.LambdaType { - return func(ctx *context.Context) error { - *content = strings.Join(*outs, "\n---\n") - return nil - } -} - func (s *step2EncryptFile) Execute(ctx *context.Context) error { err := utils.EncryptFile(s.source, s.dest, s.secret) if err != nil { diff --git a/internal/task/task/common/create_pool.go b/internal/task/task/common/create_pool.go index eca5b1810..dd6ffaa29 100644 --- a/internal/task/task/common/create_pool.go +++ b/internal/task/task/common/create_pool.go @@ -94,7 +94,7 @@ func prepare(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (clusterPoolJson var clusterPool configure.CurveClusterTopo clusterPool, err = getClusterPool(curveadm, dc) if err != nil { - return + return clusterPoolJson, clusterMDSAddrs, err } // 2. scale out cluster or migrate servers @@ -112,14 +112,14 @@ func prepare(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (clusterPoolJson var bytes []byte bytes, err = json.Marshal(clusterPool) if err != nil { - return + return clusterPoolJson, clusterMDSAddrs, err } clusterPoolJson = string(bytes) // cluster MDS address clusterMDSAddrs, err = dc.GetVariables().Get("cluster_mds_addr") clusterMDSAddrs = strings.Replace(clusterMDSAddrs, ",", " ", -1) - return + return clusterPoolJson, clusterMDSAddrs, err } func checkWaitMDSElectionSuccess(success *bool, out *string) step.LambdaType { @@ -210,7 +210,7 @@ func NewCreateTopologyTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (* return nil, err } build.DEBUG(build.DEBUG_CREATE_POOL, - build.Field{"pool json", clusterPoolJson}) + build.Field{Key: "pool json", Value: clusterPoolJson}) t.AddStep(&step.ListContainers{ ShowAll: true, diff --git a/internal/task/task/common/restart_service.go b/internal/task/task/common/restart_service.go index 25915a7e3..9f81741c3 100644 --- a/internal/task/task/common/restart_service.go +++ b/internal/task/task/common/restart_service.go @@ -30,24 +30,12 @@ import ( "github.com/opencurve/curveadm/cli/cli" "github.com/opencurve/curveadm/internal/configure/topology" - "github.com/opencurve/curveadm/internal/errno" "github.com/opencurve/curveadm/internal/task/context" "github.com/opencurve/curveadm/internal/task/step" "github.com/opencurve/curveadm/internal/task/task" tui "github.com/opencurve/curveadm/internal/tui/common" ) -func checkContainerStatus(host, role, containerId string, status *string) step.LambdaType { - return func(ctx *context.Context) error { - if *status != "running" { - return errno.ERR_CONTAINER_IS_ABNORMAL. - F("host=%s role=%s containerId=%s", - host, role, tui.TrimContainerId(containerId)) - } - return nil - } -} - func WaitContainerStart(seconds int) step.LambdaType { return func(ctx *context.Context) error { time.Sleep(time.Duration(seconds)) diff --git a/internal/task/task/common/sync_config.go b/internal/task/task/common/sync_config.go index 4cbbeb527..ba1243b39 100644 --- a/internal/task/task/common/sync_config.go +++ b/internal/task/task/common/sync_config.go @@ -102,7 +102,7 @@ func newToolV2Mutate(dc *topology.DeployConfig, delimiter string, forceRender bo func newCrontab(uuid string, dc *topology.DeployConfig, reportScriptPath string) string { var period, command string - if dc.GetReportUsage() == true { + if dc.GetReportUsage() { period = func(minute, hour, day, month, week string) string { return fmt.Sprintf("%s %s %s %s %s", minute, hour, day, month, week) }("0", "*", "*", "*", "*") // every hour diff --git a/internal/task/task/monitor/clean_service.go b/internal/task/task/monitor/clean_service.go index cb9fcf373..2e7d02fa8 100644 --- a/internal/task/task/monitor/clean_service.go +++ b/internal/task/task/monitor/clean_service.go @@ -82,7 +82,7 @@ func NewCleanMonitorTask(curveadm *cli.CurveAdm, cfg *configure.MonitorConfig) ( Files: files, ExecOptions: curveadm.ExecOptions(), }) - if clean[comm.CLEAN_ITEM_CONTAINER] == true { + if clean[comm.CLEAN_ITEM_CONTAINER] { t.AddStep(&common.Step2CleanContainer{ ServiceId: serviceId, ContainerId: containerId, diff --git a/internal/task/task/playground/init.go b/internal/task/task/playground/init.go index d51c35dec..7443432df 100644 --- a/internal/task/task/playground/init.go +++ b/internal/task/task/playground/init.go @@ -48,13 +48,13 @@ const ( func newMutate(cfg interface{}, delimiter string) step.Mutate { var serviceCfg map[string]string var variables *variable.Variables - switch cfg.(type) { + switch cfg := cfg.(type) { case *topology.DeployConfig: - dc := cfg.(*topology.DeployConfig) + dc := cfg serviceCfg = dc.GetServiceConfig() variables = dc.GetVariables() case *configure.ClientConfig: - cc := cfg.(*configure.ClientConfig) + cc := cfg serviceCfg = cc.GetServiceConfig() variables = cc.GetVariables() } diff --git a/internal/task/task/task.go b/internal/task/task/task.go index 47a6fa6f2..3eb0d755b 100644 --- a/internal/task/task/task.go +++ b/internal/task/task/task.go @@ -51,7 +51,6 @@ type ( steps []Step postSteps []Step sshConfig *module.SSHConfig - context context.Context } ) diff --git a/internal/task/task/website/clean_service.go b/internal/task/task/website/clean_service.go index 3eb003083..682225488 100644 --- a/internal/task/task/website/clean_service.go +++ b/internal/task/task/website/clean_service.go @@ -51,7 +51,7 @@ func getCleanFiles(clean map[string]bool, cfg *configure.WebsiteConfig) []string func NewCleanWebsiteTask(curveadm *cli.CurveAdm, cfg *configure.WebsiteConfig) (*task.Task, error) { serviceId := curveadm.GetWebsiteServiceId(cfg.GetId()) - containerId, err := curveadm.GetContainerId(serviceId) + containerId, _ := curveadm.GetContainerId(serviceId) hc, err := curveadm.GetHost(cfg.GetHost()) if err != nil { @@ -71,7 +71,7 @@ func NewCleanWebsiteTask(curveadm *cli.CurveAdm, cfg *configure.WebsiteConfig) ( Files: files, ExecOptions: curveadm.ExecOptions(), }) - if clean[comm.CLEAN_ITEM_CONTAINER] == true { + if clean[comm.CLEAN_ITEM_CONTAINER] { t.AddStep(&common.Step2CleanContainer{ ServiceId: serviceId, ContainerId: containerId, diff --git a/internal/task/task/website/restart_service.go b/internal/task/task/website/restart_service.go index 0b32ffe6d..c714bd5e2 100644 --- a/internal/task/task/website/restart_service.go +++ b/internal/task/task/website/restart_service.go @@ -35,7 +35,7 @@ import ( func NewRestartServiceTask(curveadm *cli.CurveAdm, cfg *configure.WebsiteConfig) (*task.Task, error) { serviceId := curveadm.GetWebsiteServiceId(cfg.GetId()) - containerId, err := curveadm.GetContainerId(serviceId) + containerId, _ := curveadm.GetContainerId(serviceId) hc, err := curveadm.GetHost(cfg.GetHost()) if err != nil { diff --git a/internal/task/task/website/start_service.go b/internal/task/task/website/start_service.go index 39ce2a840..2c25ba316 100644 --- a/internal/task/task/website/start_service.go +++ b/internal/task/task/website/start_service.go @@ -35,7 +35,7 @@ import ( func NewStartServiceTask(curveadm *cli.CurveAdm, cfg *configure.WebsiteConfig) (*task.Task, error) { serviceId := curveadm.GetWebsiteServiceId(cfg.GetId()) - containerId, err := curveadm.GetContainerId(serviceId) + containerId, _ := curveadm.GetContainerId(serviceId) hc, err := curveadm.GetHost(cfg.GetHost()) if err != nil { diff --git a/internal/task/task/website/stop_service.go b/internal/task/task/website/stop_service.go index 4a100f62d..a6300b2dc 100644 --- a/internal/task/task/website/stop_service.go +++ b/internal/task/task/website/stop_service.go @@ -35,7 +35,7 @@ import ( func NewStopServiceTask(curveadm *cli.CurveAdm, cfg *configure.WebsiteConfig) (*task.Task, error) { serviceId := curveadm.GetWebsiteServiceId(cfg.GetId()) - containerId, err := curveadm.GetContainerId(serviceId) + containerId, _ := curveadm.GetContainerId(serviceId) hc, err := curveadm.GetHost(cfg.GetHost()) if err != nil { diff --git a/internal/task/task/website/sync_config.go b/internal/task/task/website/sync_config.go index 9ea98a11f..ea837f40b 100644 --- a/internal/task/task/website/sync_config.go +++ b/internal/task/task/website/sync_config.go @@ -59,7 +59,7 @@ func NewMutate(cfg *configure.WebsiteConfig, delimiter string) step.Mutate { func NewSyncConfigTask(curveadm *cli.CurveAdm, cfg *configure.WebsiteConfig) (*task.Task, error) { serviceId := curveadm.GetWebsiteServiceId(cfg.GetId()) - containerId, err := curveadm.GetContainerId(serviceId) + containerId, _ := curveadm.GetContainerId(serviceId) role, host := cfg.GetRole(), cfg.GetHost() hc, err := curveadm.GetHost(host) diff --git a/internal/task/tasks/tasks.go b/internal/task/tasks/tasks.go index a680a68dc..2e778df14 100644 --- a/internal/task/tasks/tasks.go +++ b/internal/task/tasks/tasks.go @@ -45,7 +45,7 @@ type ( Tasks struct { tasks []*task.Task monitor *monitor - wg sync.WaitGroup + wg *sync.WaitGroup progress *mpb.Progress mainBar *mpb.Bar subBar map[string]*mpb.Bar @@ -58,7 +58,7 @@ func NewTasks() *Tasks { return &Tasks{ tasks: []*task.Task{}, monitor: newMonitor(), - wg: wg, + wg: &wg, progress: mpb.New(mpb.WithWaitGroup(&wg)), mainBar: nil, subBar: map[string]*mpb.Bar{}, @@ -212,7 +212,7 @@ func (ts *Tasks) Execute(option ExecOptions) error { // execute task by concurrency for _, t := range ts.tasks { - if ts.monitor.error() != nil && option.SkipError == false { + if ts.monitor.error() != nil && !option.SkipError { break } diff --git a/internal/tasks/tasks.go b/internal/tasks/tasks.go index 6e32c9029..4f7b20a3d 100644 --- a/internal/tasks/tasks.go +++ b/internal/tasks/tasks.go @@ -47,7 +47,7 @@ type ( Tasks struct { tasks []*task.Task monitor *monitor - wg sync.WaitGroup + wg *sync.WaitGroup progress *mpb.Progress mainBar *mpb.Bar subBar map[string]*mpb.Bar @@ -60,7 +60,7 @@ func NewTasks() *Tasks { return &Tasks{ tasks: []*task.Task{}, monitor: newMonitor(), - wg: wg, + wg: &wg, progress: mpb.New(mpb.WithWaitGroup(&wg)), mainBar: nil, subBar: map[string]*mpb.Bar{}, diff --git a/internal/tui/service/status.go b/internal/tui/service/status.go index 89eaef4d0..0b16c4c8f 100644 --- a/internal/tui/service/status.go +++ b/internal/tui/service/status.go @@ -260,7 +260,7 @@ func sortMonitorStatues(statuses []monitor.MonitorStatus) { sort.Slice(statuses, func(i, j int) bool { s1, s2 := statuses[i], statuses[j] if s1.Role == s2.Role { - return s1.Host < s1.Host + return s1.Host < s2.Host } return MONITOT_ROLE_SCORE[s1.Role] < ROLE_SCORE[s2.Role] }) diff --git a/internal/utils/cobra.go b/internal/utils/cobra.go index 6693480fa..d5b4afcec 100644 --- a/internal/utils/cobra.go +++ b/internal/utils/cobra.go @@ -25,7 +25,6 @@ package utils import ( - "errors" "fmt" "io" @@ -145,7 +144,7 @@ func SetFlagErrorFunc(cmd *cobra.Command) { return nil } - return errors.New(fmt.Sprintf("%s\nSee '%s --help'.", err, cmd.CommandPath())) + return fmt.Errorf("%s\nSee '%s --help'.", err, cmd.CommandPath()) }) } diff --git a/internal/utils/common.go b/internal/utils/common.go index be9aae86a..618bbe436 100644 --- a/internal/utils/common.go +++ b/internal/utils/common.go @@ -145,7 +145,7 @@ func Str2Bool(s string) (bool, bool) { // value, ok func IsTrueStr(s string) bool { v, yes := Str2Bool(s) - return yes && v == true + return yes && v } func TrimSuffixRepeat(s, suffix string) string { diff --git a/internal/utils/map.go b/internal/utils/map.go index 0be87594d..f7d2de490 100644 --- a/internal/utils/map.go +++ b/internal/utils/map.go @@ -40,12 +40,12 @@ func NewSafeMap() *SafeMap { func (m *SafeMap) Get(key string) interface{} { if m.transaction { - val, _ := m.Map[key] + val := m.Map[key] return val } m.RLock() defer m.RUnlock() - val, _ := m.Map[key] + val := m.Map[key] return val } diff --git a/pkg/log/glg/log.go b/pkg/log/glg/log.go index 5846d12b6..16b45ce76 100644 --- a/pkg/log/glg/log.go +++ b/pkg/log/glg/log.go @@ -49,7 +49,6 @@ func convertLevel(level string) glg.LEVEL { default: return glg.DEBG } - return glg.DEBG } func Init(level, filename string) error { @@ -68,18 +67,18 @@ func Init(level, filename string) error { } func Field(key string, val interface{}) string { - switch val.(type) { + switch val := val.(type) { case bool: - return fmt.Sprintf("%s: %s", key, strconv.FormatBool(val.(bool))) + return fmt.Sprintf("%s: %s", key, strconv.FormatBool(val)) case string: return fmt.Sprintf("%s: %s", key, val) case []byte: - return fmt.Sprintf("%s: %s", key, string(val.([]byte))) + return fmt.Sprintf("%s: %s", key, string(val)) case int: case int64: return fmt.Sprintf("%s: %d", key, val) case error: - return fmt.Sprintf("%s: %s", key, val.(error).Error()) + return fmt.Sprintf("%s: %s", key, val.Error()) } return fmt.Sprintf("%s: %v", key, val) } diff --git a/pkg/log/log.go b/pkg/log/log.go index eb67ca580..b91b9f894 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -59,19 +59,19 @@ func SwitchLevel(err error) func(msg string, fields ...zap.Field) { } func Field(key string, val interface{}) zap.Field { - switch val.(type) { + switch val := val.(type) { case bool: - return zap.Bool(key, val.(bool)) + return zap.Bool(key, val) case string: - return zap.String(key, val.(string)) + return zap.String(key, val) case []byte: - return zap.String(key, string(val.([]byte))) + return zap.String(key, string(val)) case int: - return zap.Int(key, val.(int)) + return zap.Int(key, val) case int64: - return zap.Int64(key, val.(int64)) + return zap.Int64(key, val) case error: - return zap.String(key, val.(error).Error()) + return zap.String(key, val.Error()) } return zap.Skip() } diff --git a/pkg/log/zaplog/log.go b/pkg/log/zaplog/log.go index 76e22b69d..8d553ca95 100644 --- a/pkg/log/zaplog/log.go +++ b/pkg/log/zaplog/log.go @@ -61,19 +61,19 @@ func SwitchLevel(err error) func(msg string, fields ...zap.Field) { } func Field(key string, val interface{}) zap.Field { - switch val.(type) { + switch val := val.(type) { case bool: - return zap.Bool(key, val.(bool)) + return zap.Bool(key, val) case string: - return zap.String(key, val.(string)) + return zap.String(key, val) case []byte: - return zap.String(key, string(val.([]byte))) + return zap.String(key, string(val)) case int: - return zap.Int(key, val.(int)) + return zap.Int(key, val) case int64: - return zap.Int64(key, val.(int64)) + return zap.Int64(key, val) case error: - return zap.String(key, val.(error).Error()) + return zap.String(key, val.Error()) } return zap.Skip() } diff --git a/pkg/module/ssh.go b/pkg/module/ssh.go index 4e8abf889..8f2d47f79 100644 --- a/pkg/module/ssh.go +++ b/pkg/module/ssh.go @@ -72,7 +72,7 @@ func VerifyHost(host string, remote net.Addr, key ssh.PublicKey) error { return err } else if hostFound && err == nil { // handshake because public key already exists. return nil - } else if askIsHostTrusted(host, key) == false { // Ask user to check if he trust the host public key. + } else if !askIsHostTrusted(host, key) { // Ask user to check if he trust the host public key. // Make sure to return error on non trusted keys. return errors.New("you typed no, aborted!") } diff --git a/pkg/variable/variables.go b/pkg/variable/variables.go index a22fe1937..71defa40e 100644 --- a/pkg/variable/variables.go +++ b/pkg/variable/variables.go @@ -67,7 +67,7 @@ func (vars *Variables) Get(name string) (string, error) { v, ok := vars.m[name] if !ok { return "", fmt.Errorf("variable '%s' not found", name) - } else if v.Resolved == false { + } else if !v.Resolved { return "", fmt.Errorf("variable '%s' unresolved", name) } @@ -152,6 +152,9 @@ func (vars *Variables) Rendering(s string) (string, error) { func (vars *Variables) Debug() { for _, v := range vars.m { - log.Info("Variable", log.Field(v.Name, v.Value)) + err := log.Info("Variable", log.Field(v.Name, v.Value)) + if err != nil { + return + } } }