Skip to content

Commit 8643461

Browse files
committed
refactor: interface{} -> any
```sh rg -l 'interface\{\}' | xargs sed -i 's@interface{}@any@g' ```
1 parent 0cc99c2 commit 8643461

File tree

9 files changed

+35
-35
lines changed

9 files changed

+35
-35
lines changed

client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (c *Workwx) WithApp(corpSecret string, agentID int64) *WorkwxApp {
6363
return &app
6464
}
6565

66-
func (c *WorkwxApp) composeQyapiURL(path string, req interface{}) (*url.URL, error) {
66+
func (c *WorkwxApp) composeQyapiURL(path string, req any) (*url.URL, error) {
6767
values := url.Values{}
6868
if valuer, ok := req.(urlValuer); ok {
6969
values = valuer.intoURLValues()
@@ -81,7 +81,7 @@ func (c *WorkwxApp) composeQyapiURL(path string, req interface{}) (*url.URL, err
8181
return base, nil
8282
}
8383

84-
func (c *WorkwxApp) composeQyapiURLWithToken(path string, req interface{}, withAccessToken bool) (*url.URL, error) {
84+
func (c *WorkwxApp) composeQyapiURLWithToken(path string, req any, withAccessToken bool) (*url.URL, error) {
8585
url, err := c.composeQyapiURL(path, req)
8686
if err != nil {
8787
return nil, err
@@ -103,7 +103,7 @@ func (c *WorkwxApp) composeQyapiURLWithToken(path string, req interface{}, withA
103103
return url, nil
104104
}
105105

106-
func (c *WorkwxApp) executeQyapiGet(path string, req urlValuer, respObj interface{}, withAccessToken bool) error {
106+
func (c *WorkwxApp) executeQyapiGet(path string, req urlValuer, respObj any, withAccessToken bool) error {
107107
url, err := c.composeQyapiURLWithToken(path, req, withAccessToken)
108108
if err != nil {
109109
return err
@@ -125,7 +125,7 @@ func (c *WorkwxApp) executeQyapiGet(path string, req urlValuer, respObj interfac
125125
return nil
126126
}
127127

128-
func (c *WorkwxApp) executeQyapiJSONPost(path string, req bodyer, respObj interface{}, withAccessToken bool) error {
128+
func (c *WorkwxApp) executeQyapiJSONPost(path string, req bodyer, respObj any, withAccessToken bool) error {
129129
url, err := c.composeQyapiURLWithToken(path, req, withAccessToken)
130130
if err != nil {
131131
return err
@@ -155,7 +155,7 @@ func (c *WorkwxApp) executeQyapiJSONPost(path string, req bodyer, respObj interf
155155
func (c *WorkwxApp) executeQyapiMediaUpload(
156156
path string,
157157
req mediaUploader,
158-
respObj interface{},
158+
respObj any,
159159
withAccessToken bool,
160160
) error {
161161
url, err := c.composeQyapiURLWithToken(path, req, withAccessToken)

internal/errcodegen/emit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type goEmitter struct {
3030

3131
var _ emitter = (*goEmitter)(nil)
3232

33-
func (e *goEmitter) e(format string, a ...interface{}) (n int, err error) {
33+
func (e *goEmitter) e(format string, a ...any) (n int, err error) {
3434
return fmt.Fprintf(&e.buf, format, a...)
3535
}
3636

internal/errcodegen/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var h5Regexp = regexp.MustCompile(`<h5[^>]*>.*</h5>`)
3333

3434
var mdLinkRegexp = regexp.MustCompile(`\[([^\]]+)\]\((https?://[^)]+)\)`)
3535

36-
func die(format string, a ...interface{}) {
36+
func die(format string, a ...any) {
3737
fmt.Fprintf(os.Stderr, format, a...)
3838
os.Exit(1)
3939
// unreachable

internal/sdkcodegen/emit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type goEmitter struct {
2323

2424
var _ emitter = (*goEmitter)(nil)
2525

26-
func (e *goEmitter) e(format string, a ...interface{}) (n int, err error) {
26+
func (e *goEmitter) e(format string, a ...any) (n int, err error) {
2727
return fmt.Fprintf(&e.buf, format, a...)
2828
}
2929

message.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (c *WorkwxApp) SendTextMessage(
1313
content string,
1414
isSafe bool,
1515
) error {
16-
return c.sendMessage(recipient, "text", map[string]interface{}{"content": content}, isSafe)
16+
return c.sendMessage(recipient, "text", map[string]any{"content": content}, isSafe)
1717
}
1818

1919
// SendImageMessage 发送图片消息
@@ -28,7 +28,7 @@ func (c *WorkwxApp) SendImageMessage(
2828
return c.sendMessage(
2929
recipient,
3030
"image",
31-
map[string]interface{}{
31+
map[string]any{
3232
"media_id": mediaID,
3333
}, isSafe,
3434
)
@@ -46,7 +46,7 @@ func (c *WorkwxApp) SendVoiceMessage(
4646
return c.sendMessage(
4747
recipient,
4848
"voice",
49-
map[string]interface{}{
49+
map[string]any{
5050
"media_id": mediaID,
5151
}, isSafe,
5252
)
@@ -66,7 +66,7 @@ func (c *WorkwxApp) SendVideoMessage(
6666
return c.sendMessage(
6767
recipient,
6868
"video",
69-
map[string]interface{}{
69+
map[string]any{
7070
"media_id": mediaID,
7171
"description": description, // TODO: 零值
7272
"title": title, // TODO: 零值
@@ -86,7 +86,7 @@ func (c *WorkwxApp) SendFileMessage(
8686
return c.sendMessage(
8787
recipient,
8888
"file",
89-
map[string]interface{}{
89+
map[string]any{
9090
"media_id": mediaID,
9191
}, isSafe,
9292
)
@@ -107,7 +107,7 @@ func (c *WorkwxApp) SendTextCardMessage(
107107
return c.sendMessage(
108108
recipient,
109109
"textcard",
110-
map[string]interface{}{
110+
map[string]any{
111111
"title": title,
112112
"description": description,
113113
"url": url,
@@ -128,7 +128,7 @@ func (c *WorkwxApp) SendNewsMessage(
128128
return c.sendMessage(
129129
recipient,
130130
"news",
131-
map[string]interface{}{
131+
map[string]any{
132132
"articles": articles,
133133
}, isSafe,
134134
)
@@ -146,7 +146,7 @@ func (c *WorkwxApp) SendMPNewsMessage(
146146
return c.sendMessage(
147147
recipient,
148148
"mpnews",
149-
map[string]interface{}{
149+
map[string]any{
150150
"articles": mparticles,
151151
}, isSafe,
152152
)
@@ -163,7 +163,7 @@ func (c *WorkwxApp) SendMarkdownMessage(
163163
content string,
164164
isSafe bool,
165165
) error {
166-
return c.sendMessage(recipient, "markdown", map[string]interface{}{"content": content}, isSafe)
166+
return c.sendMessage(recipient, "markdown", map[string]any{"content": content}, isSafe)
167167
}
168168

169169
// SendTaskCardMessage 发送 任务卡片 消息
@@ -179,7 +179,7 @@ func (c *WorkwxApp) SendTaskCardMessage(
179179
return c.sendMessage(
180180
recipient,
181181
"taskcard",
182-
map[string]interface{}{
182+
map[string]any{
183183
"title": title,
184184
"description": description,
185185
"url": url,
@@ -198,7 +198,7 @@ func (c *WorkwxApp) SendTemplateCardMessage(
198198
return c.sendMessage(
199199
recipient,
200200
"template_card",
201-
map[string]interface{}{
201+
map[string]any{
202202
"template_card": templateCard,
203203
}, isSafe,
204204
)
@@ -213,7 +213,7 @@ func (c *WorkwxApp) SendTemplateCardMessage(
213213
func (c *WorkwxApp) sendMessage(
214214
recipient *Recipient,
215215
msgtype string,
216-
content map[string]interface{},
216+
content map[string]any,
217217
isSafe bool,
218218
) error {
219219
sendRequestFunc := c.execMessageSend

models.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"time"
99
)
1010

11-
func marshalIntoJSONBody(x interface{}) ([]byte, error) {
11+
func marshalIntoJSONBody(x any) ([]byte, error) {
1212
y, err := json.Marshal(x)
1313
if err != nil {
1414
// should never happen unless OOM or similar bad things
@@ -101,7 +101,7 @@ type reqMessage struct {
101101
OpenKfID string
102102
Code string
103103
MsgType string
104-
Content map[string]interface{}
104+
Content map[string]any
105105
IsSafe bool
106106
}
107107

@@ -114,7 +114,7 @@ func (x reqMessage) intoBody() ([]byte, error) {
114114
safeInt = 1
115115
}
116116

117-
obj := map[string]interface{}{
117+
obj := map[string]any{
118118
"msgtype": x.MsgType,
119119
"agentid": x.AgentID,
120120
"safe": safeInt,

models_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestRespCommon(t *testing.T) {
7070

7171
func TestReqMessage(t *testing.T) {
7272
c.Convey("构造 reqMessage", t, func() {
73-
content := map[string]interface{}{"content": "test"}
73+
content := map[string]any{"content": "test"}
7474
a := reqMessage{
7575
AgentID: 233,
7676
MsgType: "text",
@@ -87,7 +87,7 @@ func TestReqMessage(t *testing.T) {
8787
})
8888

8989
c.Convey("故意放一个不能 marshal 的 Content", func() {
90-
a.Content = map[string]interface{}{
90+
a.Content = map[string]any{
9191
"heh": make(chan struct{}),
9292
}
9393

@@ -121,11 +121,11 @@ func TestReqMessage(t *testing.T) {
121121
"text": {"content": "test"},
122122
"safe": 1
123123
}`)
124-
var expected map[string]interface{}
124+
var expected map[string]any
125125
err := json.Unmarshal(expectedPayload, &expected)
126126
c.So(err, c.ShouldBeNil)
127127

128-
var actual map[string]interface{}
128+
var actual map[string]any
129129
err = json.Unmarshal(result, &actual)
130130
c.So(err, c.ShouldBeNil)
131131

@@ -154,11 +154,11 @@ func TestReqMessage(t *testing.T) {
154154
"text": {"content": "test"},
155155
"safe": 0
156156
}`)
157-
var expected map[string]interface{}
157+
var expected map[string]any
158158
err := json.Unmarshal(expectedPayload, &expected)
159159
c.So(err, c.ShouldBeNil)
160160

161-
var actual map[string]interface{}
161+
var actual map[string]any
162162
err = json.Unmarshal(result, &actual)
163163
c.So(err, c.ShouldBeNil)
164164

webhook_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (c *WebhookClient) Key() string {
3434
return c.key
3535
}
3636

37-
func (c *WebhookClient) composeQyapiURLWithKey(path string, req interface{}) (*url.URL, error) {
37+
func (c *WebhookClient) composeQyapiURLWithKey(path string, req any) (*url.URL, error) {
3838
values := url.Values{}
3939
if valuer, ok := req.(urlValuer); ok {
4040
values = valuer.intoURLValues()
@@ -55,7 +55,7 @@ func (c *WebhookClient) composeQyapiURLWithKey(path string, req interface{}) (*u
5555
return base, nil
5656
}
5757

58-
func (c *WebhookClient) executeQyapiJSONPost(path string, req interface{}, respObj interface{}) error {
58+
func (c *WebhookClient) executeQyapiJSONPost(path string, req any, respObj any) error {
5959
url, err := c.composeQyapiURLWithKey(path, req)
6060
if err != nil {
6161
return err

webhook_message.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (c *WebhookClient) SendTextMessage(
2020
content string,
2121
mentions *Mentions,
2222
) error {
23-
params := map[string]interface{}{
23+
params := map[string]any{
2424
"content": content,
2525
}
2626

@@ -44,7 +44,7 @@ func (c *WebhookClient) SendTextMessage(
4444
func (c *WebhookClient) SendMarkdownMessage(
4545
content string,
4646
) error {
47-
params := map[string]interface{}{
47+
params := map[string]any{
4848
"content": content,
4949
}
5050

@@ -54,9 +54,9 @@ func (c *WebhookClient) SendMarkdownMessage(
5454
// sendMessage 发送消息底层接口
5555
func (c *WebhookClient) sendMessage(
5656
msgtype string,
57-
content map[string]interface{},
57+
content map[string]any,
5858
) error {
59-
req := map[string]interface{}{
59+
req := map[string]any{
6060
"msgtype": msgtype,
6161
msgtype: content,
6262
}

0 commit comments

Comments
 (0)