Update lint

tags/v1.3.2 v1.3.2
Stanly 3 years ago
parent b9fe8c9ef2
commit 9a3d7a87fd

@ -1,125 +0,0 @@
linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
# don't enable:
# - gochecknoglobals
# - gocognit
# - godox
# - maligned
# - prealloc
issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
run:
skip-dirs:
- test/testdata_etc
- internal/cache
- internal/renameio
- internal/robustio
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.23.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"

@ -1,6 +1,6 @@
module git.simts.cc/common/lib
go 1.14
go 1.17
require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
@ -8,3 +8,10 @@ require (
go.uber.org/zap v1.15.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
)
require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75 // indirect
)

@ -9,10 +9,8 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mojocn/base64Captcha v1.3.1 h1:2Wbkt8Oc8qjmNJ5GyOfSo4tgVQPsbKMftqASnq8GlT0=
github.com/mojocn/base64Captcha v1.3.1/go.mod h1:wAQCKEc5bDujxKRmbT6/vTnTt5CjStQ8bRfPWUuz/iY=
@ -56,7 +54,6 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=

@ -19,7 +19,9 @@ func CompressImage(input interface{}, output string) (err error) {
if file, err = os.Open(input.(string)); err != nil {
return err
}
defer file.(*os.File).Close()
defer func() {
_ = file.(*os.File).Close()
}()
defer os.Remove(input.(string))
case *multipart.FileHeader:
@ -28,7 +30,9 @@ func CompressImage(input interface{}, output string) (err error) {
if err != nil {
return err
}
defer file.(multipart.File).Close()
defer func() {
_ = file.(multipart.File).Close()
}()
}
bs, err := ioutil.ReadAll(file)

@ -48,7 +48,7 @@ func (smsget *SmsGet) Send(mobile, msg string) (int, error) {
if err := json.Unmarshal(bs, &res); err != nil {
return 0, ErrResponse
}
if res.Status == false || res.Code != 0 {
if !res.Status || res.Code != 0 {
if res.Code == 9 {
return 0, ErrNotEnoughCredit
}

@ -31,9 +31,11 @@ func (data Data) GetString(key string) (string, error) {
return "", err
}
switch value.(type) {
switch value := value.(type) {
case []byte:
return string(value), nil
case string:
return value.(string), nil
return value, nil
}
return "", ErrFormat
@ -45,23 +47,48 @@ func (data Data) MustGetString(key string) string {
return value
}
// GetBytes 取得字串
func (data Data) GetBytes(key string) ([]byte, error) {
value, err := data.Get(key)
if err != nil {
return nil, err
}
switch value := value.(type) {
case []byte:
return value, nil
case string:
return []byte(value), nil
}
return nil, ErrFormat
}
// MustGetBytes 強制取得字串
func (data Data) MustGetBytes(key string) []byte {
value, _ := data.GetBytes(key)
return value
}
// GetSlice 取得切片
func (data Data) GetSlice(key string) (res []interface{}, err error) {
func (data Data) GetSlice(key string) (res Slice, err error) {
value, err := data.Get(key)
if err != nil {
return nil, err
}
switch value.(type) {
switch value := value.(type) {
case []interface{}:
return value.([]interface{}), nil
return Slice(value), nil
case Slice:
return value, nil
default:
return nil, ErrFormat
}
}
// MustGetSlice 強制取得切片
func (data Data) MustGetSlice(key string) []interface{} {
func (data Data) MustGetSlice(key string) Slice {
values, _ := data.GetSlice(key)
return values
}
@ -74,9 +101,9 @@ func (data Data) GetStringSlice(key string) (res []string, err error) {
}
for _, v := range values {
switch v.(type) {
switch v := v.(type) {
case string:
res = append(res, v.(string))
res = append(res, v)
default:
return nil, ErrFormat
}
@ -99,9 +126,9 @@ func (data Data) GetIntSlice(key string) (res []int, err error) {
}
for _, v := range values {
switch v.(type) {
switch v := v.(type) {
case float64:
res = append(res, int(v.(float64)))
res = append(res, int(v))
default:
return nil, ErrFormat
}
@ -123,11 +150,11 @@ func (data Data) GetData(key string) (Data, error) {
return nil, err
}
switch value.(type) {
switch value := value.(type) {
case map[string]interface{}:
return Data(value.(map[string]interface{})), nil
return Data(value), nil
case Data:
return value.(Data), nil
return value, nil
default:
return nil, ErrFormat
}
@ -148,10 +175,9 @@ func (data Data) GetDataSlice(key string) ([]Data, error) {
var vals []Data
for _, v := range values {
switch v.(type) {
switch v := v.(type) {
case map[string]interface{}:
val := v.(map[string]interface{})
vals = append(vals, Data(val))
vals = append(vals, Data(v))
default:
return nil, ErrFormat
}
@ -173,9 +199,11 @@ func (data Data) GetFloat64(key string) (float64, error) {
return 0, err
}
switch value.(type) {
switch value := value.(type) {
case float32:
return float64(value), nil
case float64:
return value.(float64), nil
return value, nil
}
return 0, ErrFormat
@ -194,32 +222,32 @@ func (data Data) GetInt64(key string) (int64, error) {
return 0, err
}
switch value.(type) {
switch value := value.(type) {
case int:
return int64(value.(int)), nil
return int64(value), nil
case uint:
return int64(value.(uint)), nil
return int64(value), nil
case int8:
return int64(value.(int8)), nil
return int64(value), nil
case uint8:
return int64(value.(uint8)), nil
return int64(value), nil
case int16:
return int64(value.(int16)), nil
return int64(value), nil
case uint16:
return int64(value.(uint16)), nil
return int64(value), nil
case int32:
return int64(value.(int32)), nil
return int64(value), nil
case uint32:
return int64(value.(uint32)), nil
return int64(value), nil
case int64:
return value.(int64), nil
return value, nil
case float64:
return int64(value.(float64)), nil
return int64(value), nil
}
return 0, ErrFormat
@ -366,9 +394,11 @@ func (data Data) GetBool(key string) (bool, error) {
return false, err
}
switch value.(type) {
switch value := value.(type) {
case uint8:
return value == 1, nil
case bool:
return value.(bool), nil
return value, nil
}
return false, ErrFormat
@ -387,9 +417,21 @@ func (data Data) GetTimestamp(key string) (Timestamp, error) {
return 0, err
}
switch value.(type) {
switch value := value.(type) {
case int:
return Timestamp(value), nil
case uint:
return Timestamp(value), nil
case int32:
return Timestamp(value), nil
case uint32:
return Timestamp(value), nil
case int64:
return Timestamp(value), nil
case uint64:
return Timestamp(value), nil
case Timestamp:
return value.(Timestamp), nil
return value, nil
}
return 0, ErrFormat
@ -424,10 +466,9 @@ func (data Data) GetPage(key string) (*Page, error) {
return nil, err
}
switch value.(type) {
switch value := value.(type) {
case Page:
page := value.(Page)
return &page, nil
return &value, nil
}
return nil, ErrFormat

@ -16,7 +16,7 @@ func (slice *Slice) Pop() (value interface{}) {
length := len(*slice)
if length > 0 {
value = (*slice)[length-1]
*slice = append((*slice)[:length-1])
*slice = (*slice)[:length-1]
}
return value

Loading…
Cancel
Save