Skip to content

Commit cdcb93d

Browse files
committed
No reason to use pointers to arrays.
1 parent 4d758f1 commit cdcb93d

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

configs.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,13 +1070,13 @@ func (GetChatMemberConfig) method() string {
10701070
// InvoiceConfig contains information for sendInvoice request.
10711071
type InvoiceConfig struct {
10721072
BaseChat
1073-
Title string // required
1074-
Description string // required
1075-
Payload string // required
1076-
ProviderToken string // required
1077-
StartParameter string // required
1078-
Currency string // required
1079-
Prices *[]LabeledPrice // required
1073+
Title string // required
1074+
Description string // required
1075+
Payload string // required
1076+
ProviderToken string // required
1077+
StartParameter string // required
1078+
Currency string // required
1079+
Prices []LabeledPrice // required
10801080
ProviderData string
10811081
PhotoURL string
10821082
PhotoSize int
@@ -1132,7 +1132,7 @@ func (config InvoiceConfig) method() string {
11321132
type ShippingConfig struct {
11331133
ShippingQueryID string // required
11341134
OK bool // required
1135-
ShippingOptions *[]ShippingOption
1135+
ShippingOptions []ShippingOption
11361136
ErrorMessage string
11371137
}
11381138

helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ func NewCallbackWithAlert(id, text string) CallbackConfig {
737737
}
738738

739739
// NewInvoice creates a new Invoice request to the user.
740-
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices *[]LabeledPrice) InvoiceConfig {
740+
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices []LabeledPrice) InvoiceConfig {
741741
return InvoiceConfig{
742742
BaseChat: BaseChat{ChatID: chatID},
743743
Title: title,

types.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ type Message struct {
147147
MediaGroupID string `json:"media_group_id"` // optional
148148
AuthorSignature string `json:"author_signature"` // optional
149149
Text string `json:"text"` // optional
150-
Entities *[]MessageEntity `json:"entities"` // optional
151-
CaptionEntities *[]MessageEntity `json:"caption_entities"` // optional
150+
Entities []MessageEntity `json:"entities"` // optional
151+
CaptionEntities []MessageEntity `json:"caption_entities"` // optional
152152
Audio *Audio `json:"audio"` // optional
153153
Document *Document `json:"document"` // optional
154154
Animation *ChatAnimation `json:"animation"` // optional
155155
Game *Game `json:"game"` // optional
156-
Photo *[]PhotoSize `json:"photo"` // optional
156+
Photo []PhotoSize `json:"photo"` // optional
157157
Sticker *Sticker `json:"sticker"` // optional
158158
Video *Video `json:"video"` // optional
159159
VideoNote *VideoNote `json:"video_note"` // optional
@@ -162,10 +162,10 @@ type Message struct {
162162
Contact *Contact `json:"contact"` // optional
163163
Location *Location `json:"location"` // optional
164164
Venue *Venue `json:"venue"` // optional
165-
NewChatMembers *[]User `json:"new_chat_members"` // optional
165+
NewChatMembers []User `json:"new_chat_members"` // optional
166166
LeftChatMember *User `json:"left_chat_member"` // optional
167167
NewChatTitle string `json:"new_chat_title"` // optional
168-
NewChatPhoto *[]PhotoSize `json:"new_chat_photo"` // optional
168+
NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional
169169
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
170170
GroupChatCreated bool `json:"group_chat_created"` // optional
171171
SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
@@ -186,11 +186,11 @@ func (m *Message) Time() time.Time {
186186

187187
// IsCommand returns true if message starts with a "bot_command" entity.
188188
func (m *Message) IsCommand() bool {
189-
if m.Entities == nil || len(*m.Entities) == 0 {
189+
if m.Entities == nil || len(m.Entities) == 0 {
190190
return false
191191
}
192192

193-
entity := (*m.Entities)[0]
193+
entity := m.Entities[0]
194194
return entity.Offset == 0 && entity.Type == "bot_command"
195195
}
196196

@@ -220,7 +220,7 @@ func (m *Message) CommandWithAt() string {
220220
}
221221

222222
// IsCommand() checks that the message begins with a bot_command entity
223-
entity := (*m.Entities)[0]
223+
entity := m.Entities[0]
224224
return m.Text[1:entity.Length]
225225
}
226226

@@ -239,7 +239,7 @@ func (m *Message) CommandArguments() string {
239239
}
240240

241241
// IsCommand() checks that the message begins with a bot_command entity
242-
entity := (*m.Entities)[0]
242+
entity := m.Entities[0]
243243

244244
if len(m.Text) == entity.Length {
245245
return "" // The command makes up the whole message
@@ -795,9 +795,9 @@ type OrderInfo struct {
795795

796796
// ShippingOption represents one shipping option.
797797
type ShippingOption struct {
798-
ID string `json:"id"`
799-
Title string `json:"title"`
800-
Prices *[]LabeledPrice `json:"prices"`
798+
ID string `json:"id"`
799+
Title string `json:"title"`
800+
Prices []LabeledPrice `json:"prices"`
801801
}
802802

803803
// SuccessfulPayment contains basic information about a successful payment.

types_test.go

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

4848
func TestMessageIsCommandWithCommand(t *testing.T) {
4949
message := tgbotapi.Message{Text: "/command"}
50-
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
50+
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
5151

5252
if !message.IsCommand() {
5353
t.Fail()
@@ -72,7 +72,7 @@ func TestIsCommandWithEmptyText(t *testing.T) {
7272

7373
func TestCommandWithCommand(t *testing.T) {
7474
message := tgbotapi.Message{Text: "/command"}
75-
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
75+
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
7676

7777
if message.Command() != "command" {
7878
t.Fail()
@@ -97,7 +97,7 @@ func TestCommandWithNonCommand(t *testing.T) {
9797

9898
func TestCommandWithBotName(t *testing.T) {
9999
message := tgbotapi.Message{Text: "/command@testbot"}
100-
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
100+
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
101101

102102
if message.Command() != "command" {
103103
t.Fail()
@@ -106,7 +106,7 @@ func TestCommandWithBotName(t *testing.T) {
106106

107107
func TestCommandWithAtWithBotName(t *testing.T) {
108108
message := tgbotapi.Message{Text: "/command@testbot"}
109-
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
109+
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
110110

111111
if message.CommandWithAt() != "command@testbot" {
112112
t.Fail()
@@ -115,15 +115,15 @@ func TestCommandWithAtWithBotName(t *testing.T) {
115115

116116
func TestMessageCommandArgumentsWithArguments(t *testing.T) {
117117
message := tgbotapi.Message{Text: "/command with arguments"}
118-
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
118+
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
119119
if message.CommandArguments() != "with arguments" {
120120
t.Fail()
121121
}
122122
}
123123

124124
func TestMessageCommandArgumentsWithMalformedArguments(t *testing.T) {
125125
message := tgbotapi.Message{Text: "/command-without argument space"}
126-
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
126+
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
127127
if message.CommandArguments() != "without argument space" {
128128
t.Fail()
129129
}

0 commit comments

Comments
 (0)