Skip to content

Commit cc95c14

Browse files
authored
run go fix (#92)
1 parent 7367dd3 commit cc95c14

File tree

10 files changed

+40
-49
lines changed

10 files changed

+40
-49
lines changed

examples/echobot/echobot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/keybase/go-keybase-chat-bot/kbchat"
99
)
1010

11-
func fail(msg string, args ...interface{}) {
11+
func fail(msg string, args ...any) {
1212
fmt.Fprintf(os.Stderr, msg+"\n", args...)
1313
os.Exit(3)
1414
}

examples/helloworld/helloworld.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/keybase/go-keybase-chat-bot/kbchat"
99
)
1010

11-
func fail(msg string, args ...interface{}) {
11+
func fail(msg string, args ...any) {
1212
fmt.Fprintf(os.Stderr, msg+"\n", args...)
1313
os.Exit(3)
1414
}

examples/secret_storage/secret_storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func (r *RentalBotClient) ListTools() ([]string, error) {
446446
return tools, nil
447447
}
448448

449-
func fail(msg string, args ...interface{}) {
449+
func fail(msg string, args ...any) {
450450
fmt.Fprintf(os.Stderr, msg+"\n", args...)
451451
os.Exit(3)
452452
}

kbchat/chat.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ type sendMessageBody struct {
2424
}
2525

2626
type sendMessageOptions struct {
27-
Channel chat1.ChatChannel `json:"channel,omitempty"`
27+
Channel chat1.ChatChannel `json:"channel"`
2828
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
29-
Message sendMessageBody `json:",omitempty"`
30-
Filename string `json:"filename,omitempty"`
31-
Title string `json:"title,omitempty"`
32-
MsgID chat1.MessageID `json:"message_id,omitempty"`
33-
ConfirmLumenSend bool `json:"confirm_lumen_send"`
34-
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
29+
Message sendMessageBody
30+
Filename string `json:"filename,omitempty"`
31+
Title string `json:"title,omitempty"`
32+
MsgID chat1.MessageID `json:"message_id,omitempty"`
33+
ConfirmLumenSend bool `json:"confirm_lumen_send"`
34+
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
3535
}
3636

3737
type sendMessageParams struct {
@@ -122,7 +122,7 @@ func (a *API) GetTextMessages(channel chat1.ChatChannel, unreadOnly bool) ([]cha
122122
return res, nil
123123
}
124124

125-
func (a *API) SendMessage(channel chat1.ChatChannel, body string, args ...interface{}) (resp SendResponse, err error) {
125+
func (a *API) SendMessage(channel chat1.ChatChannel, body string, args ...any) (resp SendResponse, err error) {
126126
defer a.Trace(&err, "SendMessage")()
127127
arg := newSendArg(sendMessageOptions{
128128
Channel: channel,
@@ -133,14 +133,14 @@ func (a *API) SendMessage(channel chat1.ChatChannel, body string, args ...interf
133133
return a.doSend(arg)
134134
}
135135

136-
func (a *API) Broadcast(body string, args ...interface{}) (SendResponse, error) {
136+
func (a *API) Broadcast(body string, args ...any) (SendResponse, error) {
137137
return a.SendMessage(chat1.ChatChannel{
138138
Name: a.GetUsername(),
139139
Public: true,
140140
}, body, args...)
141141
}
142142

143-
func (a *API) SendMessageByConvID(convID chat1.ConvIDStr, body string, args ...interface{}) (resp SendResponse, err error) {
143+
func (a *API) SendMessageByConvID(convID chat1.ConvIDStr, body string, args ...any) (resp SendResponse, err error) {
144144
defer a.Trace(&err, "SendMessageByConvID")()
145145
arg := newSendArg(sendMessageOptions{
146146
ConversationID: convID,
@@ -152,7 +152,7 @@ func (a *API) SendMessageByConvID(convID chat1.ConvIDStr, body string, args ...i
152152
}
153153

154154
// SendMessageByTlfName sends a message on the given TLF name
155-
func (a *API) SendMessageByTlfName(tlfName string, body string, args ...interface{}) (resp SendResponse, err error) {
155+
func (a *API) SendMessageByTlfName(tlfName string, body string, args ...any) (resp SendResponse, err error) {
156156
defer a.Trace(&err, "SendMessageByTlfName")()
157157
arg := newSendArg(sendMessageOptions{
158158
Channel: chat1.ChatChannel{
@@ -165,7 +165,7 @@ func (a *API) SendMessageByTlfName(tlfName string, body string, args ...interfac
165165
return a.doSend(arg)
166166
}
167167

168-
func (a *API) SendMessageByTeamName(teamName string, inChannel *string, body string, args ...interface{}) (resp SendResponse, err error) {
168+
func (a *API) SendMessageByTeamName(teamName string, inChannel *string, body string, args ...any) (resp SendResponse, err error) {
169169
defer a.Trace(&err, "SendMessageByTeamName")()
170170
channel := "general"
171171
if inChannel != nil {
@@ -184,7 +184,7 @@ func (a *API) SendMessageByTeamName(teamName string, inChannel *string, body str
184184
return a.doSend(arg)
185185
}
186186

187-
func (a *API) SendReply(channel chat1.ChatChannel, replyTo *chat1.MessageID, body string, args ...interface{}) (SendResponse, error) {
187+
func (a *API) SendReply(channel chat1.ChatChannel, replyTo *chat1.MessageID, body string, args ...any) (SendResponse, error) {
188188
arg := newSendArg(sendMessageOptions{
189189
Channel: channel,
190190
Message: sendMessageBody{
@@ -195,7 +195,7 @@ func (a *API) SendReply(channel chat1.ChatChannel, replyTo *chat1.MessageID, bod
195195
return a.doSend(arg)
196196
}
197197

198-
func (a *API) SendReplyByConvID(convID chat1.ConvIDStr, replyTo *chat1.MessageID, body string, args ...interface{}) (SendResponse, error) {
198+
func (a *API) SendReplyByConvID(convID chat1.ConvIDStr, replyTo *chat1.MessageID, body string, args ...any) (SendResponse, error) {
199199
arg := newSendArg(sendMessageOptions{
200200
ConversationID: convID,
201201
Message: sendMessageBody{
@@ -206,7 +206,7 @@ func (a *API) SendReplyByConvID(convID chat1.ConvIDStr, replyTo *chat1.MessageID
206206
return a.doSend(arg)
207207
}
208208

209-
func (a *API) SendReplyByTlfName(tlfName string, replyTo *chat1.MessageID, body string, args ...interface{}) (SendResponse, error) {
209+
func (a *API) SendReplyByTlfName(tlfName string, replyTo *chat1.MessageID, body string, args ...any) (SendResponse, error) {
210210
arg := newSendArg(sendMessageOptions{
211211
Channel: chat1.ChatChannel{
212212
Name: tlfName,
@@ -418,7 +418,7 @@ func (a *API) LeaveChannel(teamName string, channelName string) (chat1.EmptyRes,
418418
// Send lumens in chat /////////////////////////////////
419419
////////////////////////////////////////////////////////
420420

421-
func (a *API) InChatSend(channel chat1.ChatChannel, body string, args ...interface{}) (SendResponse, error) {
421+
func (a *API) InChatSend(channel chat1.ChatChannel, body string, args ...any) (SendResponse, error) {
422422
arg := newSendArg(sendMessageOptions{
423423
Channel: channel,
424424
Message: sendMessageBody{
@@ -429,7 +429,7 @@ func (a *API) InChatSend(channel chat1.ChatChannel, body string, args ...interfa
429429
return a.doSend(arg)
430430
}
431431

432-
func (a *API) InChatSendByConvID(convID chat1.ConvIDStr, body string, args ...interface{}) (SendResponse, error) {
432+
func (a *API) InChatSendByConvID(convID chat1.ConvIDStr, body string, args ...any) (SendResponse, error) {
433433
arg := newSendArg(sendMessageOptions{
434434
ConversationID: convID,
435435
Message: sendMessageBody{
@@ -440,7 +440,7 @@ func (a *API) InChatSendByConvID(convID chat1.ConvIDStr, body string, args ...in
440440
return a.doSend(arg)
441441
}
442442

443-
func (a *API) InChatSendByTlfName(tlfName string, body string, args ...interface{}) (SendResponse, error) {
443+
func (a *API) InChatSendByTlfName(tlfName string, body string, args ...any) (SendResponse, error) {
444444
arg := newSendArg(sendMessageOptions{
445445
Channel: chat1.ChatChannel{
446446
Name: tlfName,
@@ -501,7 +501,7 @@ type clearCmdsParams struct {
501501

502502
type clearCmdsArg struct {
503503
Method string `json:"method"`
504-
Params clearCmdsParams `json:"params,omitempty"`
504+
Params clearCmdsParams `json:"params"`
505505
}
506506

507507
func (a *API) ClearCommands(filter *chat1.ClearCommandAPIParam) error {
@@ -517,7 +517,7 @@ func (a *API) ClearCommands(filter *chat1.ClearCommandAPIParam) error {
517517
}
518518

519519
type listCmdsOptions struct {
520-
Channel chat1.ChatChannel `json:"channel,omitempty"`
520+
Channel chat1.ChatChannel `json:"channel"`
521521
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
522522
}
523523

@@ -572,7 +572,7 @@ func (a *API) listCommands(arg listCmdsArg) ([]chat1.UserBotCommandOutput, error
572572
}
573573

574574
type listMembersOptions struct {
575-
Channel chat1.ChatChannel `json:"channel,omitempty"`
575+
Channel chat1.ChatChannel `json:"channel"`
576576
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
577577
}
578578

@@ -636,7 +636,7 @@ type GetMessagesResult struct {
636636
}
637637

638638
type getMessagesOptions struct {
639-
Channel chat1.ChatChannel `json:"channel,omitempty"`
639+
Channel chat1.ChatChannel `json:"channel"`
640640
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
641641
MessageIDs []chat1.MessageID `json:"message_ids,omitempty"`
642642
}

kbchat/chat_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package kbchat
33
import (
44
"os"
55
"path"
6+
"slices"
67
"testing"
78

89
"github.com/keybase/go-keybase-chat-bot/kbchat/types/chat1"
@@ -167,13 +168,7 @@ func TestListChannels(t *testing.T) {
167168
channels, err := alice.ListChannels(teamChannel.Name)
168169
require.NoError(t, err)
169170
require.True(t, len(channels) > 0)
170-
channelFound := false
171-
for _, channel := range channels {
172-
if channel == teamChannel.TopicName {
173-
channelFound = true
174-
break
175-
}
176-
}
171+
channelFound := slices.Contains(channels, teamChannel.TopicName)
177172
require.True(t, channelFound)
178173
}
179174

kbchat/kbchat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func (a *API) GetUsername() string {
370370
return a.username
371371
}
372372

373-
func (a *API) doSend(arg interface{}) (resp SendResponse, err error) {
373+
func (a *API) doSend(arg any) (resp SendResponse, err error) {
374374
bArg, err := json.Marshal(arg)
375375
if err != nil {
376376
return SendResponse{}, fmt.Errorf("unable to send arg: %+v: %v", arg, err)
@@ -583,7 +583,7 @@ func (a *API) Listen(opts ListenOptions) (sub *Subscription, err error) {
583583
if err := p.Wait(); err != nil {
584584
stderrBytes, rerr := io.ReadAll(stderr)
585585
if rerr != nil {
586-
stderrBytes = []byte(fmt.Sprintf("failed to get stderr: %v", rerr))
586+
stderrBytes = fmt.Appendf(nil, "failed to get stderr: %v", rerr)
587587
}
588588
a.Debug("Listen: failed to Wait for command, restarting pipes: %s (```%s```)", err, stderrBytes)
589589
if err := a.startPipes(); err != nil {

kbchat/kbchat_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestListenForNewTextMessages(t *testing.T) {
100100

101101
done := make(chan bool)
102102
go func() {
103-
for i := 0; i < 5; i++ {
103+
for i := range 5 {
104104
time.Sleep(time.Second)
105105
message := strconv.Itoa(i)
106106
_, err := bob.SendMessage(channel, "%s", message)
@@ -117,7 +117,7 @@ func TestListenForNewTextMessages(t *testing.T) {
117117
"4": false,
118118
}
119119

120-
for i := 0; i < 5; i++ {
120+
for range 5 {
121121
msg, err := sub.Read()
122122
require.NoError(t, err)
123123
require.Equal(t, msg.Message.Content.TypeName, "text")

kbchat/kvstore.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@ type kvstoreAPIReq struct {
2828

2929
type GetEntryRes struct {
3030
Result keybase1.KVGetResult `json:"result"`
31-
Error Error `json:"error,omitempty"`
31+
Error Error `json:"error"`
3232
}
3333

3434
type PutEntryRes struct {
3535
Result keybase1.KVPutResult `json:"result"`
36-
Error Error `json:"error,omitempty"`
36+
Error Error `json:"error"`
3737
}
3838

3939
type DeleteEntryRes struct {
4040
Result keybase1.KVDeleteEntryResult `json:"result"`
41-
Error Error `json:"error,omitempty"`
41+
Error Error `json:"error"`
4242
}
4343

4444
type ListNamespacesRes struct {
4545
Result keybase1.KVListNamespaceResult `json:"result"`
46-
Error Error `json:"error,omitempty"`
46+
Error Error `json:"error"`
4747
}
4848

4949
type ListEntryKeysRes struct {
5050
Result keybase1.KVListEntryResult `json:"result"`
51-
Error Error `json:"error,omitempty"`
51+
Error Error `json:"error"`
5252
}
5353

5454
type KVStoreAPI interface {

kbchat/kvstore_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kbchat
22

33
import (
44
"fmt"
5+
"slices"
56
"testing"
67
"time"
78

@@ -10,12 +11,7 @@ import (
1011
)
1112

1213
func contains(a []string, x string) bool {
13-
for _, n := range a {
14-
if x == n {
15-
return true
16-
}
17-
}
18-
return false
14+
return slices.Contains(a, x)
1915
}
2016

2117
func containsKey(a []keybase1.KVListEntryKey, x string) bool {

kbchat/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ func NewDebugOutput(name string) *DebugOutput {
2323
}
2424
}
2525

26-
func (d *DebugOutput) Debug(format string, args ...interface{}) {
26+
func (d *DebugOutput) Debug(format string, args ...any) {
2727
msg := fmt.Sprintf(format, args...)
2828
log.Printf("%s: %s\n", d.name, msg)
2929
}
3030

31-
func (d *DebugOutput) Trace(err *error, format string, args ...interface{}) func() {
31+
func (d *DebugOutput) Trace(err *error, format string, args ...any) func() {
3232
msg := fmt.Sprintf(format, args...)
3333
start := time.Now()
3434
log.Printf("+ %s: %s\n", d.name, msg)

0 commit comments

Comments
 (0)