From 4f0284c5a066b646edd08fb594f4a5f8ad3fa968 Mon Sep 17 00:00:00 2001 From: BaoXuebin Date: Sun, 3 Jul 2022 22:59:01 +0800 Subject: [PATCH] inte:golangci-lint --- .github/workflows/golangci-lint.yml | 45 +++++++++++++++++++++++++++++ script/bql.go | 6 ---- script/config.go | 2 +- service/ledger.go | 9 ++++-- 4 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..62dd1d8 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,45 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - main + pull_request: +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v3 + with: + go-version: 1.17 + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.29 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true \ No newline at end of file diff --git a/script/bql.go b/script/bql.go index 8e71e0c..8bacf05 100644 --- a/script/bql.go +++ b/script/bql.go @@ -163,13 +163,11 @@ func bqlRawQuery(ledgerConfig *Config, selectBql string, queryParamsPtr *QueryPa bql = fmt.Sprintf("%s %s '%s' AND", bql, typeField.Tag.Get("bql"), val) } } - break case reflect.Int: val := valueField.Int() if val != 0 { bql = fmt.Sprintf("%s %s %d AND", bql, typeField.Tag.Get("bql"), val) } - break case reflect.Bool: val := valueField.Bool() // where 前的 from 可能会带有 and @@ -179,7 +177,6 @@ func bqlRawQuery(ledgerConfig *Config, selectBql string, queryParamsPtr *QueryPa if val { bql = fmt.Sprintf("%s %s ", bql, typeField.Tag.Get("bql")) } - break } } bql = strings.TrimRight(bql, " AND") @@ -220,14 +217,12 @@ func parseResult(output string, queryResultPtr interface{}, selectOne bool) erro panic(err) } temp[jsonName] = i - break // decimal case reflect.String, reflect.Struct: v := strings.Trim(val, " ") if v != "" { temp[jsonName] = v } - break case reflect.Array, reflect.Slice: // 去除空格 strArray := strings.Split(val, ",") @@ -238,7 +233,6 @@ func parseResult(output string, queryResultPtr interface{}, selectOne bool) erro } } temp[jsonName] = notBlanks - break default: panic("Unsupported field type") } diff --git a/script/config.go b/script/config.go index cc3eef8..2a01d97 100644 --- a/script/config.go +++ b/script/config.go @@ -192,7 +192,7 @@ func GetAccountType(ledgerId string, acc string) AccountType { func IsInWhiteList(ledgerId string) bool { // ledger white list is empty, return true - if whiteList == nil || len(whiteList) == 0 { + if len(whiteList) == 0 { return true } for i := range whiteList { diff --git a/service/ledger.go b/service/ledger.go index 20be7cd..5ab5cd5 100644 --- a/service/ledger.go +++ b/service/ledger.go @@ -269,13 +269,18 @@ func copyFile(sourceFilePath string, targetFilePath string, ledgerConfig script. newTargetFilePath := targetFilePath + "/" + fi.Name() if fi.IsDir() { err = script.MkDir(newTargetFilePath) - err = copyFile(newSourceFilePath, newTargetFilePath, ledgerConfig) + if err == nil { + err = copyFile(newSourceFilePath, newTargetFilePath, ledgerConfig) + } } else if !script.FileIfExist(newTargetFilePath) { - fileContent, err := script.ReadFile(newSourceFilePath) + var fileContent, err = script.ReadFile(newSourceFilePath) if err != nil { return err } err = script.WriteFile(newTargetFilePath, strings.ReplaceAll(strings.ReplaceAll(string(fileContent), "%startDate%", ledgerConfig.StartDate), "%operatingCurrency%", ledgerConfig.OperatingCurrency)) + if err != nil { + return err + } script.LogInfo(ledgerConfig.Mail, "Success create file "+newTargetFilePath) } if err != nil {