Skip to content

Commit

Permalink
fix golangci-lint failed (silenceper#284)
Browse files Browse the repository at this point in the history
* fix golangci-lint error
  • Loading branch information
silenceper authored Jun 24, 2020
1 parent b5c70cc commit 868b31c
Show file tree
Hide file tree
Showing 31 changed files with 175 additions and 155 deletions.
53 changes: 53 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- goprintffuncname
- gosimple
- govet
- ineffassign
- interfacer
- misspell
- nolintlint
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd

# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"

linters-settings:
funlen:
lines: 66
statements: 40
6 changes: 3 additions & 3 deletions cache/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ func (mem *Memory) Set(key string, val interface{}, timeout time.Duration) (err

//Delete delete value in memcache.
func (mem *Memory) Delete(key string) error {
return mem.deleteKey(key)
mem.deleteKey(key)
return nil
}

// deleteKey
func (mem *Memory) deleteKey(key string) error {
func (mem *Memory) deleteKey(key string) {
mem.Lock()
defer mem.Unlock()
delete(mem.data, key)
return nil
}
5 changes: 1 addition & 4 deletions cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ func (r *Redis) IsExist(key string) bool {

a, _ := conn.Do("EXISTS", key)
i := a.(int64)
if i > 0 {
return true
}
return false
return i > 0
}

//Delete 删除
Expand Down
3 changes: 3 additions & 0 deletions credential/default_js_ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func GetTicketFromServer(accessToken string) (ticket ResTicket, err error) {
var response []byte
url := fmt.Sprintf(getTicketURL, accessToken)
response, err = util.HTTPGet(url)
if err != nil {
return
}
err = json.Unmarshal(response, &ticket)
if err != nil {
return
Expand Down
21 changes: 10 additions & 11 deletions miniprogram/encryptor/encryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func NewEncryptor(context *context.Context) *Encryptor {
return basic
}


var (
// ErrAppIDNotMatch appid不匹配
ErrAppIDNotMatch = errors.New("app id not match")
Expand All @@ -36,19 +35,19 @@ var (

// PlainData 用户信息/手机号信息
type PlainData struct {
OpenID string `json:"openId"`
UnionID string `json:"unionId"`
NickName string `json:"nickName"`
Gender int `json:"gender"`
City string `json:"city"`
Province string `json:"province"`
Country string `json:"country"`
AvatarURL string `json:"avatarUrl"`
Language string `json:"language"`
OpenID string `json:"openId"`
UnionID string `json:"unionId"`
NickName string `json:"nickName"`
Gender int `json:"gender"`
City string `json:"city"`
Province string `json:"province"`
Country string `json:"country"`
AvatarURL string `json:"avatarUrl"`
Language string `json:"language"`
PhoneNumber string `json:"phoneNumber"`
PurePhoneNumber string `json:"purePhoneNumber"`
CountryCode string `json:"countryCode"`
Watermark struct {
Watermark struct {
Timestamp int64 `json:"timestamp"`
AppID string `json:"appid"`
} `json:"watermark"`
Expand Down
10 changes: 4 additions & 6 deletions miniprogram/qrcode/qrcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ func (qrCode *QRCode) fetchCode(urlStr string, body interface{}) (response []byt
err = fmt.Errorf("fetchCode error : errcode=%v , errmsg=%v", result.ErrCode, result.ErrMsg)
return nil, err
}
} else if contentType == "image/jpeg" {
}
if contentType == "image/jpeg" {
// 返回文件
return response, nil
} else {
err = fmt.Errorf("fetchCode error : unknown response content type - %v", contentType)
return nil, err
}

return
err = fmt.Errorf("fetchCode error : unknown response content type - %v", contentType)
return nil, err
}

// CreateWXAQRCode 获取小程序二维码,适用于需要的码数量较少的业务场景
Expand Down
4 changes: 3 additions & 1 deletion miniprogram/subscribe/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (s *Subscribe) Send(msg *Message) (err error) {
}
uri := fmt.Sprintf("%s?access_token=%s", subscribeSendURL, accessToken)
response, err := util.PostJSON(uri, msg)

if err != nil {
return
}
return util.DecodeWithCommonError(response, "Send")
}
2 changes: 1 addition & 1 deletion miniprogram/tcb/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ func (tcb *Tcb) BatchDeleteFile(env string, fileIDList []string) (*BatchDeleteFi
}
batchDeleteFileRes := &BatchDeleteFileRes{}
err = util.DecodeWithError(response, batchDeleteFileRes, "BatchDeleteFile")
return batchDeleteFileRes, nil
return batchDeleteFileRes, err
}
Loading

0 comments on commit 868b31c

Please sign in to comment.