Skip to content

Commit

Permalink
improve comment
Browse files Browse the repository at this point in the history
  • Loading branch information
houseme committed Jul 19, 2024
1 parent 01eedc4 commit ba0a147
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 34 deletions.
11 changes: 2 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ linters:
- rowserrcheck
- staticcheck
- stylecheck
- typecheck
# - typecheck
- unconvert
- unparam
- unused
- whitespace
- revive
# - revive

issues:
include:
Expand All @@ -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:"
30 changes: 14 additions & 16 deletions officialaccount/officialaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -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
}
Expand Down Expand Up @@ -91,20 +89,20 @@ 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)
}
return officialAccount.ctx.GetAccessToken()
}

// GetOauth oauth2网页授权
// GetOauth oauth2 网页授权
func (officialAccount *OfficialAccount) GetOauth() *oauth.Oauth {
if officialAccount.oauth == nil {
officialAccount.oauth = oauth.NewOauth(officialAccount.ctx)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
12 changes: 6 additions & 6 deletions openplatform/officialaccount/officialaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// OfficialAccount 代公众号实现业务
type OfficialAccount struct {
// 授权的公众号的appID
// 授权的公众号的 appID
appID string
*officialaccount.OfficialAccount
}
Expand All @@ -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())

Check failure on line 35 in openplatform/officialaccount/officialaccount.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.16)

officialAccount.GetContext undefined (type *OfficialAccount has no field or method GetContext) (typecheck)

Check failure on line 35 in openplatform/officialaccount/officialaccount.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.16)

officialAccount.GetContext undefined (type *OfficialAccount has no field or method GetContext) (typecheck)
}

// PlatformJs 平台代获取js-sdk配置
// PlatformJs 平台代获取 js-sdk 配置
func (officialAccount *OfficialAccount) PlatformJs() *js.Js {
return js.NewJs(officialAccount.GetContext(), officialAccount.appID)

Check failure on line 40 in openplatform/officialaccount/officialaccount.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.16)

officialAccount.GetContext undefined (type *OfficialAccount has no field or method GetContext) (typecheck)

Check failure on line 40 in openplatform/officialaccount/officialaccount.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.16)

officialAccount.GetContext undefined (type *OfficialAccount has no field or method GetContext) (typecheck)
}

// DefaultAuthrAccessToken 默认获取授权ak的方法
// DefaultAuthrAccessToken 默认获取授权 ak 的方法
type DefaultAuthrAccessToken struct {
opCtx *opContext.Context
appID string
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions util/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
2 changes: 1 addition & 1 deletion work/msgaudit/client_unsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit ba0a147

Please sign in to comment.