添加golangci-lint配置

This commit is contained in:
GoEdgeLab
2023-08-08 18:36:24 +08:00
parent 7c08239ea1
commit a61426e8f6
5 changed files with 85 additions and 4 deletions

76
.golangci.yaml Normal file
View File

@@ -0,0 +1,76 @@
# https://golangci-lint.run/usage/configuration/
linters:
enable-all: true
disable:
- ifshort
- exhaustivestruct
- golint
- nosnakecase
- scopelint
- varcheck
- structcheck
- interfacer
- exhaustivestruct
- maligned
- deadcode
- dogsled
- wrapcheck
- wastedassign
- varnamelen
- testpackage
- thelper
- nilerr
- sqlclosecheck
- paralleltest
- nonamedreturns
- nlreturn
- nakedret
- ireturn
- interfacebloat
- gosmopolitan
- gomnd
- goerr113
- gochecknoglobals
- exhaustruct
- errorlint
- depguard
- exhaustive
- containedctx
- wsl
- cyclop
- dupword
- errchkjson
- contextcheck
- tagalign
- dupl
- forbidigo
- funlen
- goconst
- godox
- gosec
- lll
- nestif
- revive
- unparam
- stylecheck
- gocritic
- gofumpt
- gomoddirectives
- godot
- gofmt
- gocognit
- mirror
- gocyclo
- gochecknoinits
- gci
- maintidx
- prealloc
- goimports
- errname
- musttag
- forcetypeassert
- whitespace
- noctx
- tagliatelle
- nilnil

View File

@@ -160,7 +160,7 @@ func (this *SysLockerDAO) Increase(tx *dbs.Tx, key string, defaultValue int64) (
colValue, err := tx.FindCol(0, "INSERT INTO `"+this.Table+"` (`key`, `version`) VALUES ('"+key+"', "+types.String(defaultValue+sysLockerStep)+") ON DUPLICATE KEY UPDATE `version`=`version`+"+types.String(sysLockerStep)+"; SELECT `version` FROM `"+this.Table+"` WHERE `key`='"+key+"'") colValue, err := tx.FindCol(0, "INSERT INTO `"+this.Table+"` (`key`, `version`) VALUES ('"+key+"', "+types.String(defaultValue+sysLockerStep)+") ON DUPLICATE KEY UPDATE `version`=`version`+"+types.String(sysLockerStep)+"; SELECT `version` FROM `"+this.Table+"` WHERE `key`='"+key+"'")
if err != nil { if err != nil {
if CheckSQLErrCode(err, 1064 /** syntax error **/) { if CheckSQLErrCode(err, 1064 /** syntax error **/) {
// continue to use seperated query // continue to use separated query
err = nil err = nil
} else { } else {
return 0, err return 0, err

View File

@@ -201,7 +201,7 @@ func (this *CustomHTTPProvider) post(params maps.Map) (respData []byte, err erro
defer func() { defer func() {
_ = resp.Body.Close() _ = resp.Body.Close()
}() }()
if resp.StatusCode != 200 { if resp.StatusCode != http.StatusOK {
return nil, errors.New("status should be 200, but got '" + strconv.Itoa(resp.StatusCode) + "'") return nil, errors.New("status should be 200, but got '" + strconv.Itoa(resp.StatusCode) + "'")
} }
return io.ReadAll(resp.Body) return io.ReadAll(resp.Body)

View File

@@ -435,6 +435,11 @@ func (this *EdgeDNSAPIProvider) doAPI(path string, params map[string]any, respPt
if err != nil { if err != nil {
return err return err
} }
defer func() {
if resp.Body != nil {
_ = resp.Body.Close()
}
}()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return errors.New("invalid response status code '" + types.String(resp.StatusCode) + "'") return errors.New("invalid response status code '" + types.String(resp.StatusCode) + "'")

View File

@@ -13,9 +13,9 @@ func (this *DetailedError) Code() string {
return this.code return this.code
} }
func NewDetailedError(code string, error string) *DetailedError { func NewDetailedError(code string, errString string) *DetailedError {
return &DetailedError{ return &DetailedError{
msg: error, msg: errString,
code: code, code: code,
} }
} }