Skip to content

Commit

Permalink
feat: improve comment and upgrade golang version 1.16 (#604)
Browse files Browse the repository at this point in the history
* feat: improve action config and code comment

* feat: improve comment and upgrade golang version 1.16

* feat: improve import
  • Loading branch information
houseme authored Aug 23, 2022
1 parent df62164 commit a8f7a24
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 64 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ jobs:
golangci:
strategy:
matrix:
go-version: [1.15.x,1.16.x,1.17.x]
go-version: [1.16.x,1.17.x,1.18.x]
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.1.0
uses: golangci/golangci-lint-action@v3.2.0
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
version: latest
build:
name: Test
runs-on: ubuntu-latest
Expand All @@ -38,7 +38,7 @@ jobs:
# strategy set
strategy:
matrix:
go: ["1.15", "1.16", "1.17", "1.18"]
go: ["1.16", "1.17", "1.18"]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ Package wechat provide wechat sdk for go
更多信息:https://github.com/silenceper/wechat
*/

// Package wechat provide wechat sdk for go
package wechat
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/silenceper/wechat/v2

go 1.15
go 1.16

require (
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d
Expand Down
1 change: 1 addition & 0 deletions miniprogram/tcb/cloudfunction.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type InvokeCloudFunctionRes struct {
}

// InvokeCloudFunction 云函数调用
//
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/functions/invokeCloudFunction.html
func (tcb *Tcb) InvokeCloudFunction(env, name, args string) (*InvokeCloudFunctionRes, error) {
accessToken, err := tcb.GetAccessToken()
Expand Down
11 changes: 11 additions & 0 deletions miniprogram/tcb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ type DatabaseCountRes struct {
}

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

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

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

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

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

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

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

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

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

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

// DatabaseCount 统计集合记录数或统计查询语句对应的结果记录数
//
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCount.html
func (tcb *Tcb) DatabaseCount(env, query string) (*DatabaseCountRes, error) {
accessToken, err := tcb.GetAccessToken()
Expand Down
3 changes: 3 additions & 0 deletions miniprogram/tcb/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type BatchDeleteFileRes struct {
}

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

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

// BatchDeleteFile 批量删除文件
//
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/batchDeleteFile.html
func (tcb *Tcb) BatchDeleteFile(env string, fileIDList []string) (*BatchDeleteFileRes, error) {
accessToken, err := tcb.GetAccessToken()
Expand Down
2 changes: 1 addition & 1 deletion officialaccount/customerservice/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (csm *Manager) UploadHeadImg(kfAccount, fileName string) (err error) {
return
}

//SendTypingStatus 下发客服输入状态给用户
// SendTypingStatus 下发客服输入状态给用户
func (csm *Manager) SendTypingStatus(openid string, cmd TypingStatus) (err error) {
var accessToken string
accessToken, err = csm.GetAccessToken()
Expand Down
1 change: 1 addition & 0 deletions officialaccount/material/material.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ type reqBatchGetMaterial struct {
}

// BatchGetMaterial 批量获取永久素材
//
//reference:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
func (material *Material) BatchGetMaterial(permanentMaterialType PermanentMaterialType, offset, count int64) (list ArticleList, err error) {
var accessToken string
Expand Down
12 changes: 6 additions & 6 deletions officialaccount/message/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ func (tpl *Subscribe) Delete(templateID string) (err error) {

// PublicTemplateCategory 公众号类目
type PublicTemplateCategory struct {
ID int `json:"id"` //类目ID
Name string `json:"name"` //类目的中文名
ID int `json:"id"` // 类目ID
Name string `json:"name"` // 类目的中文名
}

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

type resPublicTemplateKeyWordsList struct {
util.CommonError
KeyWordsList []*PublicTemplateKeyWords `json:"data"` //关键词列表
KeyWordsList []*PublicTemplateKeyWords `json:"data"` // 关键词列表
}

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

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

// GetPublicTemplateTitleList 获取类目下的公共模板
Expand Down
10 changes: 5 additions & 5 deletions officialaccount/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
"encoding/xml"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"runtime/debug"
"strconv"
"strings"

log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"

"github.com/silenceper/wechat/v2/officialaccount/context"
"github.com/silenceper/wechat/v2/officialaccount/message"
"github.com/silenceper/wechat/v2/util"
"github.com/tidwall/gjson"
)

// Server struct
Expand Down Expand Up @@ -106,7 +106,7 @@ func (srv *Server) handleRequest() (reply *message.Reply, err error) {
srv.isSafeMode = true
}

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

Expand Down Expand Up @@ -162,7 +162,7 @@ func (srv *Server) getMessage() (interface{}, error) {
return nil, fmt.Errorf("消息解密失败, err=%v", err)
}
} else {
rawXMLMsgBytes, err = ioutil.ReadAll(srv.Request.Body)
rawXMLMsgBytes, err = io.ReadAll(srv.Request.Body)
if err != nil {
return nil, fmt.Errorf("从body中解析xml失败, err=%v", err)
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func (srv *Server) parseRequestMessage(rawXMLMsgBytes []byte) (msg *message.MixM
err = xml.Unmarshal(rawXMLMsgBytes, msg)
return
}
//parse json
// parse json
err = json.Unmarshal(rawXMLMsgBytes, msg)
if err != nil {
return
Expand Down
1 change: 1 addition & 0 deletions openplatform/miniprogram/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type AccountBasicInfo struct {
}

// GetAccountBasicInfo 获取小程序基础信息
//
//reference:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Mini_Program_Information_Settings.html
func (basic *Basic) GetAccountBasicInfo() (*AccountBasicInfo, error) {
ak, err := basic.GetAuthrAccessToken(basic.AppID)
Expand Down
17 changes: 8 additions & 9 deletions util/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -38,7 +37,7 @@ func HTTPGetContext(ctx context.Context, uri string) ([]byte, error) {
if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
}
return ioutil.ReadAll(response.Body)
return io.ReadAll(response.Body)
}

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

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

// PostJSONWithRespContentType post json数据请求,且返回数据类型
Expand All @@ -110,7 +109,7 @@ func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, e
if response.StatusCode != http.StatusOK {
return nil, "", fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
}
responseData, err := ioutil.ReadAll(response.Body)
responseData, err := io.ReadAll(response.Body)
contentType := response.Header.Get("Content-Type")
return responseData, contentType, err
}
Expand Down Expand Up @@ -183,7 +182,7 @@ func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte
if resp.StatusCode != http.StatusOK {
return nil, err
}
respBody, err = ioutil.ReadAll(resp.Body)
respBody, err = io.ReadAll(resp.Body)
return
}

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

// httpWithTLS CA证书
func httpWithTLS(rootCa, key string) (*http.Client, error) {
var client *http.Client
certData, err := ioutil.ReadFile(rootCa)
certData, err := os.ReadFile(rootCa)
if err != nil {
return nil, fmt.Errorf("unable to find cert path=%s, error=%v", rootCa, err)
}
Expand Down Expand Up @@ -269,5 +268,5 @@ func PostXMLWithTLS(uri string, obj interface{}, ca, key string) ([]byte, error)
if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("http code error : uri=%v , statusCode=%v", uri, response.StatusCode)
}
return ioutil.ReadAll(response.Body)
return io.ReadAll(response.Body)
}
Loading

0 comments on commit a8f7a24

Please sign in to comment.