Skip to content

Commit a8f7a24

Browse files
authored
feat: improve comment and upgrade golang version 1.16 (#604)
* feat: improve action config and code comment * feat: improve comment and upgrade golang version 1.16 * feat: improve import
1 parent df62164 commit a8f7a24

File tree

13 files changed

+84
-64
lines changed

13 files changed

+84
-64
lines changed

.github/workflows/go.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ jobs:
1010
golangci:
1111
strategy:
1212
matrix:
13-
go-version: [1.15.x,1.16.x,1.17.x]
13+
go-version: [1.16.x,1.17.x,1.18.x]
1414
name: golangci-lint
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/setup-go@v2
18-
- uses: actions/checkout@v2
17+
- uses: actions/setup-go@v3
18+
- uses: actions/checkout@v3
1919
- name: golangci-lint
20-
uses: golangci/golangci-lint-action@v3.1.0
20+
uses: golangci/golangci-lint-action@v3.2.0
2121
with:
2222
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
23-
version: v1.31
23+
version: latest
2424
build:
2525
name: Test
2626
runs-on: ubuntu-latest
@@ -38,7 +38,7 @@ jobs:
3838
# strategy set
3939
strategy:
4040
matrix:
41-
go: ["1.15", "1.16", "1.17", "1.18"]
41+
go: ["1.16", "1.17", "1.18"]
4242

4343
steps:
4444
- uses: actions/checkout@v2

doc.go

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ Package wechat provide wechat sdk for go
77
更多信息:https://github.com/silenceper/wechat
88
99
*/
10+
11+
// Package wechat provide wechat sdk for go
1012
package wechat

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/silenceper/wechat/v2
22

3-
go 1.15
3+
go 1.16
44

55
require (
66
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d

miniprogram/tcb/cloudfunction.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type InvokeCloudFunctionRes struct {
1818
}
1919

2020
// InvokeCloudFunction 云函数调用
21+
//
2122
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/functions/invokeCloudFunction.html
2223
func (tcb *Tcb) InvokeCloudFunction(env, name, args string) (*InvokeCloudFunctionRes, error) {
2324
accessToken, err := tcb.GetAccessToken()

miniprogram/tcb/database.go

+11
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ type DatabaseCountRes struct {
192192
}
193193

194194
// DatabaseMigrateImport 数据库导入
195+
//
195196
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateImport.html
196197
func (tcb *Tcb) DatabaseMigrateImport(req *DatabaseMigrateImportReq) (*DatabaseMigrateImportRes, error) {
197198
accessToken, err := tcb.GetAccessToken()
@@ -209,6 +210,7 @@ func (tcb *Tcb) DatabaseMigrateImport(req *DatabaseMigrateImportReq) (*DatabaseM
209210
}
210211

211212
// DatabaseMigrateExport 数据库导出
213+
//
212214
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateExport.html
213215
func (tcb *Tcb) DatabaseMigrateExport(req *DatabaseMigrateExportReq) (*DatabaseMigrateExportRes, error) {
214216
accessToken, err := tcb.GetAccessToken()
@@ -226,6 +228,7 @@ func (tcb *Tcb) DatabaseMigrateExport(req *DatabaseMigrateExportReq) (*DatabaseM
226228
}
227229

228230
// DatabaseMigrateQueryInfo 数据库迁移状态查询
231+
//
229232
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateQueryInfo.html
230233
func (tcb *Tcb) DatabaseMigrateQueryInfo(env string, jobID int64) (*DatabaseMigrateQueryInfoRes, error) {
231234
accessToken, err := tcb.GetAccessToken()
@@ -261,6 +264,7 @@ func (tcb *Tcb) UpdateIndex(req *UpdateIndexReq) error {
261264
}
262265

263266
// DatabaseCollectionAdd 新增集合
267+
//
264268
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionAdd.html
265269
func (tcb *Tcb) DatabaseCollectionAdd(env, collectionName string) error {
266270
accessToken, err := tcb.GetAccessToken()
@@ -279,6 +283,7 @@ func (tcb *Tcb) DatabaseCollectionAdd(env, collectionName string) error {
279283
}
280284

281285
// DatabaseCollectionDelete 删除集合
286+
//
282287
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionDelete.html
283288
func (tcb *Tcb) DatabaseCollectionDelete(env, collectionName string) error {
284289
accessToken, err := tcb.GetAccessToken()
@@ -297,6 +302,7 @@ func (tcb *Tcb) DatabaseCollectionDelete(env, collectionName string) error {
297302
}
298303

299304
// DatabaseCollectionGet 获取特定云环境下集合信息
305+
//
300306
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionGet.html
301307
func (tcb *Tcb) DatabaseCollectionGet(env string, limit, offset int64) (*DatabaseCollectionGetRes, error) {
302308
accessToken, err := tcb.GetAccessToken()
@@ -318,6 +324,7 @@ func (tcb *Tcb) DatabaseCollectionGet(env string, limit, offset int64) (*Databas
318324
}
319325

320326
// DatabaseAdd 数据库插入记录
327+
//
321328
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseAdd.html
322329
func (tcb *Tcb) DatabaseAdd(env, query string) (*DatabaseAddRes, error) {
323330
accessToken, err := tcb.GetAccessToken()
@@ -338,6 +345,7 @@ func (tcb *Tcb) DatabaseAdd(env, query string) (*DatabaseAddRes, error) {
338345
}
339346

340347
// DatabaseDelete 数据库插入记录
348+
//
341349
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseDelete.html
342350
func (tcb *Tcb) DatabaseDelete(env, query string) (*DatabaseDeleteRes, error) {
343351
accessToken, err := tcb.GetAccessToken()
@@ -358,6 +366,7 @@ func (tcb *Tcb) DatabaseDelete(env, query string) (*DatabaseDeleteRes, error) {
358366
}
359367

360368
// DatabaseUpdate 数据库插入记录
369+
//
361370
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseUpdate.html
362371
func (tcb *Tcb) DatabaseUpdate(env, query string) (*DatabaseUpdateRes, error) {
363372
accessToken, err := tcb.GetAccessToken()
@@ -378,6 +387,7 @@ func (tcb *Tcb) DatabaseUpdate(env, query string) (*DatabaseUpdateRes, error) {
378387
}
379388

380389
// DatabaseQuery 数据库查询记录
390+
//
381391
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseQuery.html
382392
func (tcb *Tcb) DatabaseQuery(env, query string) (*DatabaseQueryRes, error) {
383393
accessToken, err := tcb.GetAccessToken()
@@ -398,6 +408,7 @@ func (tcb *Tcb) DatabaseQuery(env, query string) (*DatabaseQueryRes, error) {
398408
}
399409

400410
// DatabaseCount 统计集合记录数或统计查询语句对应的结果记录数
411+
//
401412
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCount.html
402413
func (tcb *Tcb) DatabaseCount(env, query string) (*DatabaseCountRes, error) {
403414
accessToken, err := tcb.GetAccessToken()

miniprogram/tcb/file.go

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type BatchDeleteFileRes struct {
7171
}
7272

7373
// UploadFile 上传文件
74+
//
7475
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/uploadFile.html
7576
func (tcb *Tcb) UploadFile(env, path string) (*UploadFileRes, error) {
7677
accessToken, err := tcb.GetAccessToken()
@@ -92,6 +93,7 @@ func (tcb *Tcb) UploadFile(env, path string) (*UploadFileRes, error) {
9293
}
9394

9495
// BatchDownloadFile 获取文件下载链接
96+
//
9597
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/batchDownloadFile.html
9698
func (tcb *Tcb) BatchDownloadFile(env string, fileList []*DownloadFile) (*BatchDownloadFileRes, error) {
9799
accessToken, err := tcb.GetAccessToken()
@@ -113,6 +115,7 @@ func (tcb *Tcb) BatchDownloadFile(env string, fileList []*DownloadFile) (*BatchD
113115
}
114116

115117
// BatchDeleteFile 批量删除文件
118+
//
116119
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/batchDeleteFile.html
117120
func (tcb *Tcb) BatchDeleteFile(env string, fileIDList []string) (*BatchDeleteFileRes, error) {
118121
accessToken, err := tcb.GetAccessToken()

officialaccount/customerservice/manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (csm *Manager) UploadHeadImg(kfAccount, fileName string) (err error) {
228228
return
229229
}
230230

231-
//SendTypingStatus 下发客服输入状态给用户
231+
// SendTypingStatus 下发客服输入状态给用户
232232
func (csm *Manager) SendTypingStatus(openid string, cmd TypingStatus) (err error) {
233233
var accessToken string
234234
accessToken, err = csm.GetAccessToken()

officialaccount/material/material.go

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ type reqBatchGetMaterial struct {
302302
}
303303

304304
// BatchGetMaterial 批量获取永久素材
305+
//
305306
//reference:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
306307
func (material *Material) BatchGetMaterial(permanentMaterialType PermanentMaterialType, offset, count int64) (list ArticleList, err error) {
307308
var accessToken string

officialaccount/message/subscribe.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ func (tpl *Subscribe) Delete(templateID string) (err error) {
151151

152152
// PublicTemplateCategory 公众号类目
153153
type PublicTemplateCategory struct {
154-
ID int `json:"id"` //类目ID
155-
Name string `json:"name"` //类目的中文名
154+
ID int `json:"id"` // 类目ID
155+
Name string `json:"name"` // 类目的中文名
156156
}
157157

158158
type resSubscribeCategoryList struct {
@@ -186,13 +186,13 @@ func (tpl *Subscribe) GetCategory() (categoryList []*PublicTemplateCategory, err
186186
type PublicTemplateKeyWords struct {
187187
KeyWordsID int `json:"kid"` // 关键词 id
188188
Name string `json:"name"` // 关键词内容
189-
Example string `json:"example"` //关键词内容对应的示例
189+
Example string `json:"example"` // 关键词内容对应的示例
190190
Rule string `json:"rule"` // 参数类型
191191
}
192192

193193
type resPublicTemplateKeyWordsList struct {
194194
util.CommonError
195-
KeyWordsList []*PublicTemplateKeyWords `json:"data"` //关键词列表
195+
KeyWordsList []*PublicTemplateKeyWords `json:"data"` // 关键词列表
196196
}
197197

198198
// GetPubTplKeyWordsByID 获取模板中的关键词
@@ -227,8 +227,8 @@ type PublicTemplateTitle struct {
227227

228228
type resPublicTemplateTitleList struct {
229229
util.CommonError
230-
Count int `json:"count"` //公共模板列表总数
231-
TemplateTitleList []*PublicTemplateTitle `json:"data"` //模板标题列表
230+
Count int `json:"count"` // 公共模板列表总数
231+
TemplateTitleList []*PublicTemplateTitle `json:"data"` // 模板标题列表
232232
}
233233

234234
// GetPublicTemplateTitleList 获取类目下的公共模板

officialaccount/server/server.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import (
55
"encoding/xml"
66
"errors"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"reflect"
1111
"runtime/debug"
1212
"strconv"
1313
"strings"
1414

1515
log "github.com/sirupsen/logrus"
16+
"github.com/tidwall/gjson"
1617

1718
"github.com/silenceper/wechat/v2/officialaccount/context"
1819
"github.com/silenceper/wechat/v2/officialaccount/message"
1920
"github.com/silenceper/wechat/v2/util"
20-
"github.com/tidwall/gjson"
2121
)
2222

2323
// Server struct
@@ -106,7 +106,7 @@ func (srv *Server) handleRequest() (reply *message.Reply, err error) {
106106
srv.isSafeMode = true
107107
}
108108

109-
//set request contentType
109+
// set request contentType
110110
contentType := srv.Request.Header.Get("Content-Type")
111111
srv.isJSONContent = strings.Contains(contentType, "application/json")
112112

@@ -162,7 +162,7 @@ func (srv *Server) getMessage() (interface{}, error) {
162162
return nil, fmt.Errorf("消息解密失败, err=%v", err)
163163
}
164164
} else {
165-
rawXMLMsgBytes, err = ioutil.ReadAll(srv.Request.Body)
165+
rawXMLMsgBytes, err = io.ReadAll(srv.Request.Body)
166166
if err != nil {
167167
return nil, fmt.Errorf("从body中解析xml失败, err=%v", err)
168168
}
@@ -193,7 +193,7 @@ func (srv *Server) parseRequestMessage(rawXMLMsgBytes []byte) (msg *message.MixM
193193
err = xml.Unmarshal(rawXMLMsgBytes, msg)
194194
return
195195
}
196-
//parse json
196+
// parse json
197197
err = json.Unmarshal(rawXMLMsgBytes, msg)
198198
if err != nil {
199199
return

openplatform/miniprogram/basic/basic.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type AccountBasicInfo struct {
2828
}
2929

3030
// GetAccountBasicInfo 获取小程序基础信息
31+
//
3132
//reference:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Mini_Program_Information_Settings.html
3233
func (basic *Basic) GetAccountBasicInfo() (*AccountBasicInfo, error) {
3334
ak, err := basic.GetAuthrAccessToken(basic.AppID)

util/http.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/xml"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"log"
1413
"mime/multipart"
1514
"net/http"
@@ -38,7 +37,7 @@ func HTTPGetContext(ctx context.Context, uri string) ([]byte, error) {
3837
if response.StatusCode != http.StatusOK {
3938
return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
4039
}
41-
return ioutil.ReadAll(response.Body)
40+
return io.ReadAll(response.Body)
4241
}
4342

4443
// HTTPPost post 请求
@@ -67,7 +66,7 @@ func HTTPPostContext(ctx context.Context, uri string, data []byte, header map[st
6766
if response.StatusCode != http.StatusOK {
6867
return nil, fmt.Errorf("http post error : uri=%v , statusCode=%v", uri, response.StatusCode)
6968
}
70-
return ioutil.ReadAll(response.Body)
69+
return io.ReadAll(response.Body)
7170
}
7271

7372
// PostJSON post json 数据请求
@@ -88,7 +87,7 @@ func PostJSON(uri string, obj interface{}) ([]byte, error) {
8887
if response.StatusCode != http.StatusOK {
8988
return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
9089
}
91-
return ioutil.ReadAll(response.Body)
90+
return io.ReadAll(response.Body)
9291
}
9392

9493
// PostJSONWithRespContentType post json数据请求,且返回数据类型
@@ -110,7 +109,7 @@ func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, e
110109
if response.StatusCode != http.StatusOK {
111110
return nil, "", fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
112111
}
113-
responseData, err := ioutil.ReadAll(response.Body)
112+
responseData, err := io.ReadAll(response.Body)
114113
contentType := response.Header.Get("Content-Type")
115114
return responseData, contentType, err
116115
}
@@ -183,7 +182,7 @@ func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte
183182
if resp.StatusCode != http.StatusOK {
184183
return nil, err
185184
}
186-
respBody, err = ioutil.ReadAll(resp.Body)
185+
respBody, err = io.ReadAll(resp.Body)
187186
return
188187
}
189188

@@ -204,13 +203,13 @@ func PostXML(uri string, obj interface{}) ([]byte, error) {
204203
if response.StatusCode != http.StatusOK {
205204
return nil, fmt.Errorf("http code error : uri=%v , statusCode=%v", uri, response.StatusCode)
206205
}
207-
return ioutil.ReadAll(response.Body)
206+
return io.ReadAll(response.Body)
208207
}
209208

210209
// httpWithTLS CA证书
211210
func httpWithTLS(rootCa, key string) (*http.Client, error) {
212211
var client *http.Client
213-
certData, err := ioutil.ReadFile(rootCa)
212+
certData, err := os.ReadFile(rootCa)
214213
if err != nil {
215214
return nil, fmt.Errorf("unable to find cert path=%s, error=%v", rootCa, err)
216215
}
@@ -269,5 +268,5 @@ func PostXMLWithTLS(uri string, obj interface{}, ca, key string) ([]byte, error)
269268
if response.StatusCode != http.StatusOK {
270269
return nil, fmt.Errorf("http code error : uri=%v , statusCode=%v", uri, response.StatusCode)
271270
}
272-
return ioutil.ReadAll(response.Body)
271+
return io.ReadAll(response.Body)
273272
}

0 commit comments

Comments
 (0)