Skip to content

Commit 9e53818

Browse files
authored
Merge pull request #109 from ArtisanCloud/develop
feature: - refact(base): refact base client new with error
2 parents e9ee3a8 + c2fb462 commit 9e53818

File tree

147 files changed

+1322
-526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+1322
-526
lines changed

go.mod

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ module github.com/ArtisanCloud/PowerWeChat/v2
22

33
go 1.17
44

5-
//replace github.com/ArtisanCloud/PowerLibs/ => ../PowerLibs
6-
//
5+
//replace github.com/ArtisanCloud/PowerLibs/v2 => ../PowerLibs
76
//replace github.com/ArtisanCloud/PowerSocialite/v2 => ../PowerSocialite
87

98
require (
10-
github.com/ArtisanCloud/PowerLibs/v2 v2.0.3
11-
github.com/ArtisanCloud/PowerSocialite/v2 v2.0.1
9+
github.com/ArtisanCloud/PowerLibs/v2 v2.0.6
10+
github.com/ArtisanCloud/PowerSocialite/v2 v2.0.2
1211
github.com/go-playground/assert/v2 v2.0.1
1312
github.com/google/uuid v1.1.1
1413
github.com/stretchr/testify v1.7.0
@@ -27,8 +26,6 @@ require (
2726
github.com/json-iterator/go v1.1.11 // indirect
2827
github.com/leodido/go-urn v1.2.1 // indirect
2928
github.com/mattn/go-isatty v0.0.14 // indirect
30-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
31-
github.com/modern-go/reflect2 v1.0.1 // indirect
3229
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
3330
github.com/pkg/errors v0.9.1 // indirect
3431
github.com/pmezard/go-difflib v1.0.0 // indirect

go.sum

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
github.com/ArtisanCloud/PowerLibs/v2 v2.0.2/go.mod h1:geiRu1Fv9YnHR8qPfV0/eGA1duOwAafR46YzYHCfviY=
2-
github.com/ArtisanCloud/PowerLibs/v2 v2.0.3 h1:0lVlUuHmLIT0EfE26lROwjydb0D0lAUN6gx1jqQVOC8=
3-
github.com/ArtisanCloud/PowerLibs/v2 v2.0.3/go.mod h1:geiRu1Fv9YnHR8qPfV0/eGA1duOwAafR46YzYHCfviY=
4-
github.com/ArtisanCloud/PowerSocialite/v2 v2.0.1 h1:8wkgBfLKt0z4OXSYzlLDvwHIypOiUHg6m1dlT+zHZKg=
5-
github.com/ArtisanCloud/PowerSocialite/v2 v2.0.1/go.mod h1:1FXnZ2A4YfWsRxW+tBiWzO13O8hJ/lb7DX/u1vCB128=
1+
github.com/ArtisanCloud/PowerLibs/v2 v2.0.6 h1:4V+VhimrbpUTgXOZ+II3cxYIMsmYlYTwFfGLm67dFvY=
2+
github.com/ArtisanCloud/PowerLibs/v2 v2.0.6/go.mod h1:+rsjtjT33wiSlvYX4M9T59pZZasQNW96r7rNKB9izZs=
3+
github.com/ArtisanCloud/PowerSocialite/v2 v2.0.2 h1:IJ9Ag5K+HsTFsYBh+mdPHum45MxThiKesPr8kOES5QE=
4+
github.com/ArtisanCloud/PowerSocialite/v2 v2.0.2/go.mod h1:4SUtaWSeTCPq9szCXSTeSu0ltHuZpVzyMuNl+6zSEeo=
65
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
76
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
87
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
@@ -67,6 +66,9 @@ github.com/guonaihong/gout v0.2.12/go.mod h1:25bJRA+9fErgSvEUF5UAazc9dME+VdkjrFu
6766
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
6867
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
6968
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
69+
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
70+
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
71+
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
7072
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
7173
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
7274
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
@@ -151,7 +153,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
151153
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
152154
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
153155
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
154-
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
156+
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
155157
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI=
156158
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
157159
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
@@ -237,3 +239,4 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
237239
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
238240
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
239241
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
242+
gorm.io/gorm v1.23.6/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func main() {
115115
configWecom := GetWorkConfig()
116116
wecomApp, err := work.NewWork(configWecom)
117117
if err != nil {
118-
fmt.Println(err.Error())
118+
panic(err.Error())
119119
}
120120
fmt2.Dump("wecom config:", wecomApp.GetConfig().All())
121121

src/basicService/contentSecurity/client.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ type Client struct {
88
BaseUri string
99
}
1010

11-
func NewClient(app *kernel.ApplicationInterface) *Client {
11+
func NewClient(app *kernel.ApplicationInterface) (*Client, error) {
1212

13+
baseClient, err := kernel.NewBaseClient(app, nil)
14+
if err != nil {
15+
return nil, err
16+
}
1317
client := &Client{
14-
BaseClient: kernel.NewBaseClient(app, nil),
18+
BaseClient: baseClient,
1519
}
1620

1721
client.BaseClient.HttpRequest.BaseURI = "https://api.weixin.qq.com/wxa/"
1822

19-
return client
23+
return client, nil
2024
}

src/basicService/contentSecurity/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
55
)
66

7-
func RegisterProvider(app kernel.ApplicationInterface) *Client {
7+
func RegisterProvider(app kernel.ApplicationInterface) (*Client, error) {
88

99
return NewClient(&app)
1010

src/basicService/jssdk/client.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ type Client struct {
2424
url string
2525
}
2626

27-
func NewClient(app *kernel.ApplicationInterface) *Client {
27+
func NewClient(app *kernel.ApplicationInterface) (*Client, error) {
28+
baseClient, err := kernel.NewBaseClient(app, nil)
29+
if err != nil {
30+
return nil, err
31+
}
2832
client := &Client{
29-
BaseClient: kernel.NewBaseClient(app, nil),
33+
BaseClient: baseClient,
3034
InteractsWithCache: &kernel.InteractsWithCache{},
3135
}
3236

3337
client.TicketEndpoint = "https://api.weixin.qq.com/cgi-bin/ticket/getticket"
3438

35-
return client
39+
return client, nil
3640
}
3741

3842
func (comp *Client) BuildConfig(jsApiList []string, debug bool, beta bool, openTagList []string, url string) (interface{}, error) {

src/basicService/jssdk/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
55
)
66

7-
func RegisterProvider(app kernel.ApplicationInterface) *Client {
7+
func RegisterProvider(app kernel.ApplicationInterface) (*Client, error) {
88

99
return NewClient(&app)
1010

src/basicService/media/client.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ type Client struct {
1616
AllowTypes []string
1717
}
1818

19-
func NewClient(app kernel.ApplicationInterface) *Client {
19+
func NewClient(app kernel.ApplicationInterface) (*Client, error) {
20+
baseClient, err := kernel.NewBaseClient(&app, nil)
21+
if err != nil {
22+
return nil, err
23+
}
2024
client := &Client{
21-
BaseClient: kernel.NewBaseClient(&app, nil),
25+
BaseClient: baseClient,
2226

2327
AllowTypes: []string{"image", "voice", "video", "thumb"},
2428
}
2529

2630
client.BaseClient.HttpRequest.BaseURI = "https://api.weixin.qq.com/cgi-bin/"
27-
return client
31+
return client, nil
2832
}
2933

3034
// 新增临时素材

src/basicService/qrCode/client.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ type Client struct {
2222
*kernel.BaseClient
2323
}
2424

25-
func NewClient(app *kernel.ApplicationInterface) *Client {
26-
25+
func NewClient(app *kernel.ApplicationInterface) (*Client, error) {
26+
baseClient, err := kernel.NewBaseClient(app, nil)
27+
if err != nil {
28+
return nil, err
29+
}
2730
client := &Client{
28-
BaseClient: kernel.NewBaseClient(app, nil),
31+
BaseClient: baseClient,
2932
}
3033

3134
client.HttpRequest.BaseURI = "https://api.weixin.qq.com/cgi-bin/"
32-
return client
35+
return client, nil
3336
}
3437

3538
// 生成永久二维码请求

src/basicService/qrCode/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
55
)
66

7-
func RegisterProvider(app kernel.ApplicationInterface) *Client {
7+
func RegisterProvider(app kernel.ApplicationInterface) (*Client, error) {
88

99
return NewClient(&app)
1010

src/basicService/subscribeMessage/provider.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import (
44
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
55
)
66

7-
func RegisterProvider(app kernel.ApplicationInterface) *Client {
7+
func RegisterProvider(app kernel.ApplicationInterface) (*Client, error) {
88

9-
return &Client{
10-
kernel.NewBaseClient(&app, nil),
9+
baseClient, err := kernel.NewBaseClient(&app, nil)
10+
if err != nil {
11+
return nil, err
1112
}
13+
return &Client{
14+
baseClient,
15+
}, nil
1216

1317
}

src/basicService/url/client.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ type Client struct {
1515
BaseUri string
1616
}
1717

18-
func NewClient(app *kernel.ApplicationInterface) *Client {
19-
18+
func NewClient(app *kernel.ApplicationInterface) (*Client, error) {
19+
baseClient, err := kernel.NewBaseClient(app, nil)
20+
if err != nil {
21+
return nil, err
22+
}
2023
client := &Client{
21-
BaseClient: kernel.NewBaseClient(app, nil),
24+
baseClient,
25+
"",
2226
}
2327
client.BaseClient.HttpRequest.BaseURI = "https://api.weixin.qq.com/"
2428

25-
return client
29+
return client, nil
2630
}
2731

2832
// 短key托管

src/basicService/url/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
55
)
66

7-
func RegisterProvider(app kernel.ApplicationInterface) *Client {
7+
func RegisterProvider(app kernel.ApplicationInterface) (*Client, error) {
88

99
return NewClient(&app)
1010

src/kernel/accessToken.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@ type AccessToken struct {
3333
GetCredentials func() *object.StringMap
3434
}
3535

36-
func NewAccessToken(app *ApplicationInterface) *AccessToken {
36+
func NewAccessToken(app *ApplicationInterface) (*AccessToken, error) {
3737
config := (*app).GetContainer().GetConfig()
3838

3939
var cacheClient cache.CacheInterface = nil
4040
if (*config)["cache"] != nil {
4141
cacheClient = (*config)["cache"].(cache.CacheInterface)
4242
}
4343

44+
httpRequest, err := request.NewHttpRequest(config)
45+
if err != nil {
46+
return nil, err
47+
}
4448
token := &AccessToken{
4549
App: app,
46-
HttpRequest: request.NewHttpRequest(config),
50+
HttpRequest: httpRequest,
4751

4852
RequestMethod: "GET",
4953
EndpointToGetToken: "",
@@ -54,7 +58,7 @@ func NewAccessToken(app *ApplicationInterface) *AccessToken {
5458
InteractsWithCache: NewInteractsWithCache(cacheClient),
5559
}
5660

57-
return token
61+
return token, nil
5862
}
5963

6064
func (accessToken *AccessToken) GetRefreshedToken() (*response2.ResponseGetToken, error) {

src/kernel/baseClient.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ type BaseClient struct {
2727
Token *AccessToken
2828
}
2929

30-
func NewBaseClient(app *ApplicationInterface, token *AccessToken) *BaseClient {
30+
func NewBaseClient(app *ApplicationInterface, token *AccessToken) (*BaseClient, error) {
3131
config := (*app).GetContainer().GetConfig()
3232

3333
if token == nil {
3434
token = (*app).GetAccessToken()
3535
}
36-
36+
httpRequest, err := request.NewHttpRequest(config)
37+
if err != nil {
38+
return nil, err
39+
}
3740
client := &BaseClient{
38-
HttpRequest: request.NewHttpRequest(config),
41+
HttpRequest: httpRequest,
3942
App: app,
4043
Token: token,
4144
}
@@ -48,7 +51,7 @@ func NewBaseClient(app *ApplicationInterface, token *AccessToken) *BaseClient {
4851
}
4952
}
5053

51-
return client
54+
return client, nil
5255

5356
}
5457

0 commit comments

Comments
 (0)