Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimized-error-handling&remove unused constant #772

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: optimized-error-handling&remove unused constant
  • Loading branch information
markwang1992 committed Mar 15, 2024
commit 6053598a03953080df3cbd62c1ed81e082f340eb
6 changes: 2 additions & 4 deletions miniprogram/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,8 @@ func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (*Get
}

var result GetPhoneNumberResponse
if err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber"); err != nil {
return nil, err
}
return &result, nil
err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber")
return &result, err
}

// GetPhoneNumber 小程序通过code获取用户手机号
Expand Down
7 changes: 1 addition & 6 deletions miniprogram/business/phone_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,5 @@ func (business *Business) GetPhoneNumber(in *GetPhoneNumberRequest) (info PhoneI
PhoneInfo PhoneInfo `json:"phone_info"`
}
err = util.DecodeWithError(response, &resp, "business.GetPhoneNumber")
if nil != err {
return
}

info = resp.PhoneInfo
return
return resp.PhoneInfo, err
}
20 changes: 4 additions & 16 deletions miniprogram/privacy/privacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ const (

// PrivacyV1 用户隐私保护指引的版本,1表示现网版本。
PrivacyV1 = 1
// PrivacyV2 2表示开发版。默认是2开发版。
PrivacyV2 = 2
houseme marked this conversation as resolved.
Show resolved Hide resolved
)

// GetPrivacySettingResponse 获取权限配置的响应结果
Expand Down Expand Up @@ -103,11 +101,8 @@ func (s *Privacy) GetPrivacySetting(privacyVer int) (GetPrivacySettingResponse,
}
// 返回错误信息
var result GetPrivacySettingResponse
if err = util.DecodeWithError(response, &result, "getprivacysetting"); err != nil {
return GetPrivacySettingResponse{}, err
}

return result, nil
err = util.DecodeWithError(response, &result, "getprivacysetting")
return result, err
}

// SetPrivacySetting 更新小程序权限配置
Expand All @@ -130,11 +125,7 @@ func (s *Privacy) SetPrivacySetting(privacyVer int, ownerSetting OwnerSetting, s
}

// 返回错误信息
if err = util.DecodeWithCommonError(response, "setprivacysetting"); err != nil {
return err
}

return err
return util.DecodeWithCommonError(response, "setprivacysetting")
}

// UploadPrivacyExtFileResponse 上传权限定义模板响应参数
Expand All @@ -159,9 +150,6 @@ func (s *Privacy) UploadPrivacyExtFile(fileData []byte) (UploadPrivacyExtFileRes

// 返回错误信息
var result UploadPrivacyExtFileResponse
if err = util.DecodeWithError(response, &result, "setprivacysetting"); err != nil {
return UploadPrivacyExtFileResponse{}, err
}

err = util.DecodeWithError(response, &result, "setprivacysetting")
return result, err
}
34 changes: 2 additions & 32 deletions miniprogram/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ func (security *Security) MediaCheckAsyncV1(in *MediaCheckAsyncV1Request) (trace
TraceID string `json:"trace_id"`
}
err = util.DecodeWithError(response, &res, "MediaCheckAsyncV1")
if err != nil {
return
}

traceID = res.TraceID
return
return res.TraceID, err
}

// MediaCheckAsyncRequest 图片/音频异步校验请求参数
Expand Down Expand Up @@ -93,12 +88,7 @@ func (security *Security) MediaCheckAsync(in *MediaCheckAsyncRequest) (traceID s
TraceID string `json:"trace_id"`
}
err = util.DecodeWithError(response, &res, "MediaCheckAsync")
if err != nil {
return
}

traceID = res.TraceID
return
return res.TraceID, err
}

// ImageCheckV1 校验一张图片是否含有违法违规内容(同步)
Expand All @@ -124,29 +114,9 @@ func (security *Security) ImageCheckV1(filename string) (err error) {
// CheckSuggest 检查建议
type CheckSuggest string

const (
// CheckSuggestRisky 违规风险建议
CheckSuggestRisky CheckSuggest = "risky"
// CheckSuggestPass 安全
CheckSuggestPass CheckSuggest = "pass"
// CheckSuggestReview 需要审查
CheckSuggestReview CheckSuggest = "review"
)

houseme marked this conversation as resolved.
Show resolved Hide resolved
// MsgScene 文本场景
type MsgScene uint8

const (
// MsgSceneMaterial 资料文件检查场景
MsgSceneMaterial MsgScene = iota + 1
// MsgSceneComment 评论
MsgSceneComment
// MsgSceneForum 论坛
MsgSceneForum
// MsgSceneSocialLog 社交日志
MsgSceneSocialLog
)

// CheckLabel 检查命中标签
type CheckLabel int

Expand Down
6 changes: 1 addition & 5 deletions miniprogram/shortlink/shortlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ func (shortLink *ShortLink) generate(shortLinkParams ShortLinker) (string, error
// 使用通用方法返回错误
var res resShortLinker
err = util.DecodeWithError(response, &res, "GenerateShortLink")
if err != nil {
return "", err
}

return res.Link, nil
return res.Link, err
}

// GenerateShortLinkPermanent 生成永久 shortLink
Expand Down
6 changes: 1 addition & 5 deletions miniprogram/subscribe/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,7 @@ func (s *Subscribe) Add(ShortID string, kidList []int, sceneDesc string) (templa
}
var result resSubscribeAdd
err = util.DecodeWithError(response, &result, "AddSubscribe")
if err != nil {
return
}
templateID = result.TemplateID
return
return result.TemplateID, err
}

// Delete 删除私有模板
Expand Down
13 changes: 1 addition & 12 deletions miniprogram/urllink/urllink.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ const generateURL = "https://api.weixin.qq.com/wxa/generate_urllink"
// TExpireType 失效类型 (指定时间戳/指定间隔)
type TExpireType int

const (
// ExpireTypeTime 指定时间戳后失效
houseme marked this conversation as resolved.
Show resolved Hide resolved
ExpireTypeTime TExpireType = 0

// ExpireTypeInterval 间隔指定天数后失效
ExpireTypeInterval TExpireType = 1
)

// ULParams 请求参数
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.generate.html#请求参数
type ULParams struct {
Expand Down Expand Up @@ -65,8 +57,5 @@ func (u *URLLink) Generate(params *ULParams) (string, error) {
}
var resp ULResult
err = util.DecodeWithError(response, &resp, "URLLink.Generate")
if err != nil {
return "", err
}
return resp.URLLink, nil
return resp.URLLink, err
}
6 changes: 1 addition & 5 deletions miniprogram/urlscheme/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,5 @@ func (u *URLScheme) QueryScheme(querySchemeParams QueryScheme) (schemeInfo Schem
// 使用通用方法返回错误
var res resQueryScheme
err = util.DecodeWithError(response, &res, "QueryScheme")
if err != nil {
return
}

return res.SchemeInfo, res.VisitOpenid, nil
return res.SchemeInfo, res.VisitOpenid, err
}
19 changes: 1 addition & 18 deletions miniprogram/urlscheme/urlscheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ type TExpireType int
// EnvVersion 要打开的小程序版本
type EnvVersion string

const (
// ExpireTypeTime 指定时间戳后失效
ExpireTypeTime TExpireType = 0
// ExpireTypeInterval 间隔指定天数后失效
ExpireTypeInterval TExpireType = 1

// EnvVersionRelease 正式版为"release"
EnvVersionRelease EnvVersion = "release"
// EnvVersionTrial 体验版为"trial"
EnvVersionTrial EnvVersion = "trial"
// EnvVersionDevelop 开发版为"develop"
EnvVersionDevelop EnvVersion = "develop"
)

// JumpWxa 跳转到的目标小程序信息
type JumpWxa struct {
Path string `json:"path"`
Expand Down Expand Up @@ -78,8 +64,5 @@ func (u *URLScheme) Generate(params *USParams) (string, error) {
}
var resp USResult
err = util.DecodeWithError(response, &resp, "URLScheme.Generate")
if err != nil {
return "", err
}
return resp.OpenLink, nil
return resp.OpenLink, err
}
7 changes: 2 additions & 5 deletions officialaccount/basic/short_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ func (basic *Basic) Long2ShortURL(longURL string) (shortURL string, err error) {
if err != nil {
return
}
if err = util.DecodeWithError(responseBytes, resp, long2shortAction); err != nil {
return
}
shortURL = resp.ShortURL
return
err = util.DecodeWithError(responseBytes, resp, long2shortAction)
return resp.ShortURL, err
}
19 changes: 2 additions & 17 deletions officialaccount/customerservice/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ const (
customerServiceTypingURL = "https://api.weixin.qq.com/cgi-bin/message/custom/typing"
)

const (
// Typing 表示正在输入状态
Typing TypingStatus = "Typing"
// CancelTyping 表示取消正在输入状态
CancelTyping TypingStatus = "CancelTyping"
)

// Manager 客服管理者,可以管理客服
type Manager struct {
*context.Context
Expand Down Expand Up @@ -72,11 +65,7 @@ func (csm *Manager) List() (customerServiceList []*KeFuInfo, err error) {
}
var res resKeFuList
err = util.DecodeWithError(response, &res, "ListCustomerService")
if err != nil {
return
}
customerServiceList = res.KfList
return
return res.KfList, err
}

// KeFuOnlineInfo 客服在线信息
Expand Down Expand Up @@ -107,11 +96,7 @@ func (csm *Manager) OnlineList() (customerServiceOnlineList []*KeFuOnlineInfo, e
}
var res resKeFuOnlineList
err = util.DecodeWithError(response, &res, "ListOnlineCustomerService")
if err != nil {
return
}
customerServiceOnlineList = res.KfOnlineList
return
return res.KfOnlineList, err
}

// Add 添加客服账号
Expand Down
28 changes: 0 additions & 28 deletions officialaccount/datacube/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,6 @@ import (
// AdSlot 广告位类型
type AdSlot string

const (
// SlotIDBizBottom 公众号底部广告
SlotIDBizBottom AdSlot = "SLOT_ID_BIZ_BOTTOM"
// SlotIDBizMidContext 公众号文中广告
SlotIDBizMidContext AdSlot = "SLOT_ID_BIZ_MID_CONTEXT"
// SlotIDBizVideoEnd 公众号视频后贴
SlotIDBizVideoEnd AdSlot = "SLOT_ID_BIZ_VIDEO_END"
// SlotIDBizSponsor 公众号互选广告
SlotIDBizSponsor AdSlot = "SLOT_ID_BIZ_SPONSOR"
// SlotIDBizCps 公众号返佣商品
SlotIDBizCps AdSlot = "SLOT_ID_BIZ_CPS"
// SlotIDWeappBanner 小程序banner
SlotIDWeappBanner AdSlot = "SLOT_ID_WEAPP_BANNER"
// SlotIDWeappRewardVideo 小程序激励视频
SlotIDWeappRewardVideo AdSlot = "SLOT_ID_WEAPP_REWARD_VIDEO"
// SlotIDWeappInterstitial 小程序插屏广告
SlotIDWeappInterstitial AdSlot = "SLOT_ID_WEAPP_INTERSTITIAL"
// SlotIDWeappVideoFeeds 小程序视频广告
SlotIDWeappVideoFeeds AdSlot = "SLOT_ID_WEAPP_VIDEO_FEEDS"
// SlotIDWeappVideoBegin 小程序视频前贴
SlotIDWeappVideoBegin AdSlot = "SLOT_ID_WEAPP_VIDEO_BEGIN"
// SlotIDWeappBox 小程序格子广告
SlotIDWeappBox AdSlot = "SLOT_ID_WEAPP_BOX"
)

const (
publisherURL = "https://api.weixin.qq.com/publisher/stat"
)
Expand Down Expand Up @@ -183,9 +158,6 @@ func (cube *DataCube) fetchData(params ParamsPublisher) (response []byte, err er
uri := fmt.Sprintf("%s?%s", publisherURL, v.Encode())

response, err = util.HTTPGet(uri)
if err != nil {
return
}
return
}

Expand Down
20 changes: 3 additions & 17 deletions officialaccount/draft/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ func (draft *Draft) AddDraft(articles []*Article) (mediaID string, err error) {
MediaID string `json:"media_id"`
}
err = util.DecodeWithError(response, &res, "AddDraft")
if err != nil {
return
}
mediaID = res.MediaID
return
return res.MediaID, err
}

// GetDraft 获取草稿
Expand All @@ -94,12 +90,7 @@ func (draft *Draft) GetDraft(mediaID string) (articles []*Article, err error) {
NewsItem []*Article `json:"news_item"`
}
err = util.DecodeWithError(response, &res, "GetDraft")
if err != nil {
return
}

articles = res.NewsItem
return
return res.NewsItem, err
}

// DeleteDraft 删除草稿
Expand Down Expand Up @@ -172,12 +163,7 @@ func (draft *Draft) CountDraft() (total uint, err error) {
Total uint `json:"total_count"`
}
err = util.DecodeWithError(response, &res, "CountDraft")
if nil != err {
return
}

total = res.Total
return
return res.Total, err
}

// ArticleList 草稿列表
Expand Down
Loading
Loading