From c0da806e0343909cad93926d0b3a581f73b9cea3 Mon Sep 17 00:00:00 2001 From: silenceper Date: Thu, 26 Nov 2020 12:25:57 +0800 Subject: [PATCH] update golangci (#349) * update golangci --- .github/workflows/go.yml | 28 ++++++++++++++++------------ .golangci.yml | 2 +- cache/cache.go | 2 +- cache/memcache.go | 10 +++++----- miniprogram/config/config.go | 8 ++++---- officialaccount/config/config.go | 2 +- pay/config/config.go | 2 +- util/crypto.go | 6 +++--- util/http.go | 12 ++++++------ 9 files changed, 38 insertions(+), 34 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ab6b1b247..68e3ed218 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,34 +7,38 @@ on: branches: [ master,release-* ] jobs: + golangci: + strategy: + matrix: + go-version: [1.15.x] + name: golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.31 build: - name: Build + name: Test runs-on: ubuntu-latest services: redis: image: redis ports: - - 6379:6379 + - 6379:6379 options: --entrypoint redis-server memcached: image: memcached ports: - 11211:11211 steps: - + - uses: actions/checkout@v2 - name: Set up Go 1.x uses: actions/setup-go@v2 with: go-version: ^1.13 id: go - - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v1 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.26 - - - name: Test run: go test -v -race ./... diff --git a/.golangci.yml b/.golangci.yml index dfd6e3b47..933f6eae7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,7 +11,7 @@ linters: - errcheck - funlen - goconst - - gocritic + # - gocritic - gocyclo - gofmt - goimports diff --git a/cache/cache.go b/cache/cache.go index d144b8f89..f3feb84c4 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -2,7 +2,7 @@ package cache import "time" -//Cache interface +// Cache interface type Cache interface { Get(key string) interface{} Set(key string, val interface{}, timeout time.Duration) error diff --git a/cache/memcache.go b/cache/memcache.go index 3dee1bc22..8271a9fe0 100644 --- a/cache/memcache.go +++ b/cache/memcache.go @@ -7,18 +7,18 @@ import ( "github.com/bradfitz/gomemcache/memcache" ) -//Memcache struct contains *memcache.Client +// Memcache struct contains *memcache.Client type Memcache struct { conn *memcache.Client } -//NewMemcache create new memcache +// NewMemcache create new memcache func NewMemcache(server ...string) *Memcache { mc := memcache.New(server...) return &Memcache{mc} } -//Get return cached value +// Get return cached value func (mem *Memcache) Get(key string) interface{} { var err error var item *memcache.Item @@ -40,7 +40,7 @@ func (mem *Memcache) IsExist(key string) bool { return true } -//Set cached value with key and expire time. +// Set cached value with key and expire time. func (mem *Memcache) Set(key string, val interface{}, timeout time.Duration) (err error) { var data []byte if data, err = json.Marshal(val); err != nil { @@ -51,7 +51,7 @@ func (mem *Memcache) Set(key string, val interface{}, timeout time.Duration) (er return mem.conn.Set(item) } -//Delete delete value in memcache. +// Delete delete value in memcache. func (mem *Memcache) Delete(key string) error { return mem.conn.Delete(key) } diff --git a/miniprogram/config/config.go b/miniprogram/config/config.go index 1be6bd2ad..b1214437d 100644 --- a/miniprogram/config/config.go +++ b/miniprogram/config/config.go @@ -1,13 +1,13 @@ -//Package config 小程序config配置 +// Package config 小程序config配置 package config import ( "github.com/silenceper/wechat/v2/cache" ) -//Config config for 小程序 +// Config config for 小程序 type Config struct { - AppID string `json:"app_id"` //appid - AppSecret string `json:"app_secret"` //appsecret + AppID string `json:"app_id"` // appid + AppSecret string `json:"app_secret"` // appsecret Cache cache.Cache } diff --git a/officialaccount/config/config.go b/officialaccount/config/config.go index 3db65fe66..7846801a2 100644 --- a/officialaccount/config/config.go +++ b/officialaccount/config/config.go @@ -4,7 +4,7 @@ import ( "github.com/silenceper/wechat/v2/cache" ) -//Config config for 微信公众号 +// Config config for 微信公众号 type Config struct { AppID string `json:"app_id"` //appid AppSecret string `json:"app_secret"` //appsecret diff --git a/pay/config/config.go b/pay/config/config.go index dc64a58a3..f5a31e46e 100644 --- a/pay/config/config.go +++ b/pay/config/config.go @@ -1,6 +1,6 @@ package config -//Config config for pay +// Config config for pay type Config struct { AppID string `json:"app_id"` MchID string `json:"mch_id"` diff --git a/util/crypto.go b/util/crypto.go index 16b5ce67b..4a9296bcf 100644 --- a/util/crypto.go +++ b/util/crypto.go @@ -20,7 +20,7 @@ const ( SignTypeHMACSHA256 = `HMAC-SHA256` ) -//EncryptMsg 加密消息 +// EncryptMsg 加密消息 func EncryptMsg(random, rawXMLMsg []byte, appID, aesKey string) (encrtptMsg []byte, err error) { defer func() { if e := recover(); e != nil { @@ -38,7 +38,7 @@ func EncryptMsg(random, rawXMLMsg []byte, appID, aesKey string) (encrtptMsg []by return } -//AESEncryptMsg ciphertext = AES_Encrypt[random(16B) + msg_len(4B) + rawXMLMsg + appId] +// AESEncryptMsg ciphertext = AES_Encrypt[random(16B) + msg_len(4B) + rawXMLMsg + appId] //参考:github.com/chanxuehong/wechat.v2 func AESEncryptMsg(random, rawXMLMsg []byte, appID string, aesKey []byte) (ciphertext []byte) { const ( @@ -76,7 +76,7 @@ func AESEncryptMsg(random, rawXMLMsg []byte, appID string, aesKey []byte) (ciphe return } -//DecryptMsg 消息解密 +// DecryptMsg 消息解密 func DecryptMsg(appID, encryptedMsg, aesKey string) (random, rawMsgXMLBytes []byte, err error) { defer func() { if e := recover(); e != nil { diff --git a/util/http.go b/util/http.go index 44b40284a..56d16505e 100644 --- a/util/http.go +++ b/util/http.go @@ -52,9 +52,9 @@ func PostJSON(uri string, obj interface{}) ([]byte, error) { if err != nil { return nil, err } - jsonData = bytes.Replace(jsonData, []byte("\\u003c"), []byte("<"), -1) - jsonData = bytes.Replace(jsonData, []byte("\\u003e"), []byte(">"), -1) - jsonData = bytes.Replace(jsonData, []byte("\\u0026"), []byte("&"), -1) + jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003c"), []byte("<")) + jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003e"), []byte(">")) + jsonData = bytes.ReplaceAll(jsonData, []byte("\\u0026"), []byte("&")) body := bytes.NewBuffer(jsonData) response, err := http.Post(uri, "application/json;charset=utf-8", body) if err != nil { @@ -75,9 +75,9 @@ func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, e return nil, "", err } - jsonData = bytes.Replace(jsonData, []byte("\\u003c"), []byte("<"), -1) - jsonData = bytes.Replace(jsonData, []byte("\\u003e"), []byte(">"), -1) - jsonData = bytes.Replace(jsonData, []byte("\\u0026"), []byte("&"), -1) + jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003c"), []byte("<")) + jsonData = bytes.ReplaceAll(jsonData, []byte("\\u003e"), []byte(">")) + jsonData = bytes.ReplaceAll(jsonData, []byte("\\u0026"), []byte("&")) body := bytes.NewBuffer(jsonData) response, err := http.Post(uri, "application/json;charset=utf-8", body)