Skip to content

Commit

Permalink
update golangci (silenceper#349)
Browse files Browse the repository at this point in the history
* update golangci
  • Loading branch information
silenceper authored Nov 26, 2020
1 parent 185baa5 commit c0da806
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 34 deletions.
28 changes: 16 additions & 12 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ linters:
- errcheck
- funlen
- goconst
- gocritic
# - gocritic
- gocyclo
- gofmt
- goimports
Expand Down
2 changes: 1 addition & 1 deletion cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions cache/memcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
}
8 changes: 4 additions & 4 deletions miniprogram/config/config.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion officialaccount/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pay/config/config.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand Down
6 changes: 3 additions & 3 deletions util/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions util/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit c0da806

Please sign in to comment.