1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-04 12:52:27 +08:00

improve comment

This commit is contained in:
houseme
2024-07-19 11:26:06 +08:00
parent 01eedc4274
commit ba0a1477eb
5 changed files with 25 additions and 34 deletions

View File

@@ -24,12 +24,12 @@ linters:
- rowserrcheck
- staticcheck
- stylecheck
- typecheck
# - typecheck
- unconvert
- unparam
- unused
- whitespace
- revive
# - revive
issues:
include:
@@ -53,10 +53,3 @@ linters-settings:
lines: 66
statements: 50
#issues:
# include:
# - EXC0002 # disable excluding of issues about comments from golint
# exclude-rules:
# - linters:
# - stylecheck
# text: "ST1000:"

View File

@@ -4,30 +4,28 @@ import (
stdcontext "context"
"net/http"
"github.com/silenceper/wechat/v2/internal/openapi"
"github.com/silenceper/wechat/v2/officialaccount/draft"
"github.com/silenceper/wechat/v2/officialaccount/freepublish"
"github.com/silenceper/wechat/v2/officialaccount/ocr"
"github.com/silenceper/wechat/v2/officialaccount/datacube"
"github.com/silenceper/wechat/v2/credential"
"github.com/silenceper/wechat/v2/internal/openapi"
"github.com/silenceper/wechat/v2/officialaccount/basic"
"github.com/silenceper/wechat/v2/officialaccount/broadcast"
"github.com/silenceper/wechat/v2/officialaccount/config"
"github.com/silenceper/wechat/v2/officialaccount/context"
"github.com/silenceper/wechat/v2/officialaccount/customerservice"
"github.com/silenceper/wechat/v2/officialaccount/datacube"
"github.com/silenceper/wechat/v2/officialaccount/device"
"github.com/silenceper/wechat/v2/officialaccount/draft"
"github.com/silenceper/wechat/v2/officialaccount/freepublish"
"github.com/silenceper/wechat/v2/officialaccount/js"
"github.com/silenceper/wechat/v2/officialaccount/material"
"github.com/silenceper/wechat/v2/officialaccount/menu"
"github.com/silenceper/wechat/v2/officialaccount/message"
"github.com/silenceper/wechat/v2/officialaccount/oauth"
"github.com/silenceper/wechat/v2/officialaccount/ocr"
"github.com/silenceper/wechat/v2/officialaccount/server"
"github.com/silenceper/wechat/v2/officialaccount/user"
)
// OfficialAccount 微信公众号相关API
// OfficialAccount 微信公众号相关 API
type OfficialAccount struct {
ctx *context.Context
basic *basic.Basic
@@ -47,7 +45,7 @@ type OfficialAccount struct {
subscribeMsg *message.Subscribe
}
// NewOfficialAccount 实例化公众号API
// NewOfficialAccount 实例化公众号 API
func NewOfficialAccount(cfg *config.Config) *OfficialAccount {
defaultAkHandle := credential.NewDefaultAccessToken(cfg.AppID, cfg.AppSecret, credential.CacheKeyOfficialAccountPrefix, cfg.Cache)
ctx := &context.Context{
@@ -57,7 +55,7 @@ func NewOfficialAccount(cfg *config.Config) *OfficialAccount {
return &OfficialAccount{ctx: ctx}
}
// SetAccessTokenHandle 自定义access_token获取方式
// SetAccessTokenHandle 自定义 access_token 获取方式
func (officialAccount *OfficialAccount) SetAccessTokenHandle(accessTokenHandle credential.AccessTokenHandle) {
officialAccount.ctx.AccessTokenHandle = accessTokenHandle
}
@@ -91,12 +89,12 @@ func (officialAccount *OfficialAccount) GetServer(req *http.Request, writer http
return srv
}
// GetAccessToken 获取access_token
// GetAccessToken 获取 access_token
func (officialAccount *OfficialAccount) GetAccessToken() (string, error) {
return officialAccount.ctx.GetAccessToken()
}
// GetAccessTokenContext 获取access_token
// GetAccessTokenContext 获取 access_token
func (officialAccount *OfficialAccount) GetAccessTokenContext(ctx stdcontext.Context) (string, error) {
if c, ok := officialAccount.ctx.AccessTokenHandle.(credential.AccessTokenContextHandle); ok {
return c.GetAccessTokenContext(ctx)
@@ -104,7 +102,7 @@ func (officialAccount *OfficialAccount) GetAccessTokenContext(ctx stdcontext.Con
return officialAccount.ctx.GetAccessToken()
}
// GetOauth oauth2网页授权
// GetOauth oauth2 网页授权
func (officialAccount *OfficialAccount) GetOauth() *oauth.Oauth {
if officialAccount.oauth == nil {
officialAccount.oauth = oauth.NewOauth(officialAccount.ctx)
@@ -136,7 +134,7 @@ func (officialAccount *OfficialAccount) GetFreePublish() *freepublish.FreePublis
return officialAccount.freepublish
}
// GetJs js-sdk配置
// GetJs js-sdk 配置
func (officialAccount *OfficialAccount) GetJs() *js.Js {
if officialAccount.js == nil {
officialAccount.js = js.NewJs(officialAccount.ctx)
@@ -193,7 +191,7 @@ func (officialAccount *OfficialAccount) GetDataCube() *datacube.DataCube {
return officialAccount.datacube
}
// GetOCR OCR接口
// GetOCR OCR 接口
func (officialAccount *OfficialAccount) GetOCR() *ocr.OCR {
if officialAccount.ocr == nil {
officialAccount.ocr = ocr.NewOCR(officialAccount.ctx)
@@ -214,7 +212,7 @@ func (officialAccount *OfficialAccount) GetCustomerServiceManager() *customerser
return customerservice.NewCustomerServiceManager(officialAccount.ctx)
}
// GetOpenAPI openApi管理接口
// GetOpenAPI openApi 管理接口
func (officialAccount *OfficialAccount) GetOpenAPI() *openapi.OpenAPI {
return openapi.NewOpenAPI(officialAccount.ctx)
}

View File

@@ -11,7 +11,7 @@ import (
// OfficialAccount 代公众号实现业务
type OfficialAccount struct {
// 授权的公众号的appID
// 授权的公众号的 appID
appID string
*officialaccount.OfficialAccount
}
@@ -25,22 +25,22 @@ func NewOfficialAccount(opCtx *opContext.Context, appID string) *OfficialAccount
Token: opCtx.Token,
Cache: opCtx.Cache,
})
// 设置获取access_token的函数
// 设置获取 access_token 的函数
officialAccount.SetAccessTokenHandle(NewDefaultAuthrAccessToken(opCtx, appID))
return &OfficialAccount{appID: appID, OfficialAccount: officialAccount}
}
// PlatformOauth 平台代发起oauth2网页授权
// PlatformOauth 平台代发起 oauth2 网页授权
func (officialAccount *OfficialAccount) PlatformOauth() *oauth.Oauth {
return oauth.NewOauth(officialAccount.GetContext())
}
// PlatformJs 平台代获取js-sdk配置
// PlatformJs 平台代获取 js-sdk 配置
func (officialAccount *OfficialAccount) PlatformJs() *js.Js {
return js.NewJs(officialAccount.GetContext(), officialAccount.appID)
}
// DefaultAuthrAccessToken 默认获取授权ak的方法
// DefaultAuthrAccessToken 默认获取授权 ak 的方法
type DefaultAuthrAccessToken struct {
opCtx *opContext.Context
appID string
@@ -54,7 +54,7 @@ func NewDefaultAuthrAccessToken(opCtx *opContext.Context, appID string) credenti
}
}
// GetAccessToken 获取ak
// GetAccessToken 获取 ak
func (ak *DefaultAuthrAccessToken) GetAccessToken() (string, error) {
return ak.opCtx.GetAuthrAccessToken(ak.appID)
}

View File

@@ -12,8 +12,8 @@ func TestQuery(t *testing.T) {
"cat": "Peter",
})
if result == "" {
// 由于hash是乱序 所以没法很好的预测输出的字符串
// 将会输出符合Query规则的字符串 "age=12&name=Alan&cat=Peter"
// 由于 hash 是乱序 所以没法很好的预测输出的字符串
// 将会输出符合 Query 规则的字符串 "age=12&name=Alan&cat=Peter"
t.Error("NOT PASS")
}
}

View File

@@ -16,5 +16,5 @@ type Client struct {
// NewClient new
func NewClient(cfg *config.Config) (*Client, error) {
return nil, fmt.Errorf("会话存档功能目前只支持Linux平台运行并且打开设置CGO_ENABLED=1")
return nil, fmt.Errorf("会话存档功能目前只支持 Linux 平台运行,并且打开设置 CGO_ENABLED=1")
}