No reason to use pointers to arrays.

bot-api-6.1
Syfaro 2018-10-08 23:32:34 -05:00
parent 4d758f17d4
commit cdcb93df5f
4 changed files with 27 additions and 27 deletions

View File

@ -1070,13 +1070,13 @@ func (GetChatMemberConfig) method() string {
// InvoiceConfig contains information for sendInvoice request.
type InvoiceConfig struct {
BaseChat
Title string // required
Description string // required
Payload string // required
ProviderToken string // required
StartParameter string // required
Currency string // required
Prices *[]LabeledPrice // required
Title string // required
Description string // required
Payload string // required
ProviderToken string // required
StartParameter string // required
Currency string // required
Prices []LabeledPrice // required
ProviderData string
PhotoURL string
PhotoSize int
@ -1132,7 +1132,7 @@ func (config InvoiceConfig) method() string {
type ShippingConfig struct {
ShippingQueryID string // required
OK bool // required
ShippingOptions *[]ShippingOption
ShippingOptions []ShippingOption
ErrorMessage string
}

View File

@ -737,7 +737,7 @@ func NewCallbackWithAlert(id, text string) CallbackConfig {
}
// NewInvoice creates a new Invoice request to the user.
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices *[]LabeledPrice) InvoiceConfig {
func NewInvoice(chatID int64, title, description, payload, providerToken, startParameter, currency string, prices []LabeledPrice) InvoiceConfig {
return InvoiceConfig{
BaseChat: BaseChat{ChatID: chatID},
Title: title,

View File

@ -147,13 +147,13 @@ type Message struct {
MediaGroupID string `json:"media_group_id"` // optional
AuthorSignature string `json:"author_signature"` // optional
Text string `json:"text"` // optional
Entities *[]MessageEntity `json:"entities"` // optional
CaptionEntities *[]MessageEntity `json:"caption_entities"` // optional
Entities []MessageEntity `json:"entities"` // optional
CaptionEntities []MessageEntity `json:"caption_entities"` // optional
Audio *Audio `json:"audio"` // optional
Document *Document `json:"document"` // optional
Animation *ChatAnimation `json:"animation"` // optional
Game *Game `json:"game"` // optional
Photo *[]PhotoSize `json:"photo"` // optional
Photo []PhotoSize `json:"photo"` // optional
Sticker *Sticker `json:"sticker"` // optional
Video *Video `json:"video"` // optional
VideoNote *VideoNote `json:"video_note"` // optional
@ -162,10 +162,10 @@ type Message struct {
Contact *Contact `json:"contact"` // optional
Location *Location `json:"location"` // optional
Venue *Venue `json:"venue"` // optional
NewChatMembers *[]User `json:"new_chat_members"` // optional
NewChatMembers []User `json:"new_chat_members"` // optional
LeftChatMember *User `json:"left_chat_member"` // optional
NewChatTitle string `json:"new_chat_title"` // optional
NewChatPhoto *[]PhotoSize `json:"new_chat_photo"` // optional
NewChatPhoto []PhotoSize `json:"new_chat_photo"` // optional
DeleteChatPhoto bool `json:"delete_chat_photo"` // optional
GroupChatCreated bool `json:"group_chat_created"` // optional
SuperGroupChatCreated bool `json:"supergroup_chat_created"` // optional
@ -186,11 +186,11 @@ func (m *Message) Time() time.Time {
// IsCommand returns true if message starts with a "bot_command" entity.
func (m *Message) IsCommand() bool {
if m.Entities == nil || len(*m.Entities) == 0 {
if m.Entities == nil || len(m.Entities) == 0 {
return false
}
entity := (*m.Entities)[0]
entity := m.Entities[0]
return entity.Offset == 0 && entity.Type == "bot_command"
}
@ -220,7 +220,7 @@ func (m *Message) CommandWithAt() string {
}
// IsCommand() checks that the message begins with a bot_command entity
entity := (*m.Entities)[0]
entity := m.Entities[0]
return m.Text[1:entity.Length]
}
@ -239,7 +239,7 @@ func (m *Message) CommandArguments() string {
}
// IsCommand() checks that the message begins with a bot_command entity
entity := (*m.Entities)[0]
entity := m.Entities[0]
if len(m.Text) == entity.Length {
return "" // The command makes up the whole message
@ -795,9 +795,9 @@ type OrderInfo struct {
// ShippingOption represents one shipping option.
type ShippingOption struct {
ID string `json:"id"`
Title string `json:"title"`
Prices *[]LabeledPrice `json:"prices"`
ID string `json:"id"`
Title string `json:"title"`
Prices []LabeledPrice `json:"prices"`
}
// SuccessfulPayment contains basic information about a successful payment.

View File

@ -47,7 +47,7 @@ func TestMessageTime(t *testing.T) {
func TestMessageIsCommandWithCommand(t *testing.T) {
message := tgbotapi.Message{Text: "/command"}
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
if !message.IsCommand() {
t.Fail()
@ -72,7 +72,7 @@ func TestIsCommandWithEmptyText(t *testing.T) {
func TestCommandWithCommand(t *testing.T) {
message := tgbotapi.Message{Text: "/command"}
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
if message.Command() != "command" {
t.Fail()
@ -97,7 +97,7 @@ func TestCommandWithNonCommand(t *testing.T) {
func TestCommandWithBotName(t *testing.T) {
message := tgbotapi.Message{Text: "/command@testbot"}
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
if message.Command() != "command" {
t.Fail()
@ -106,7 +106,7 @@ func TestCommandWithBotName(t *testing.T) {
func TestCommandWithAtWithBotName(t *testing.T) {
message := tgbotapi.Message{Text: "/command@testbot"}
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 16}}
if message.CommandWithAt() != "command@testbot" {
t.Fail()
@ -115,7 +115,7 @@ func TestCommandWithAtWithBotName(t *testing.T) {
func TestMessageCommandArgumentsWithArguments(t *testing.T) {
message := tgbotapi.Message{Text: "/command with arguments"}
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
if message.CommandArguments() != "with arguments" {
t.Fail()
}
@ -123,7 +123,7 @@ func TestMessageCommandArgumentsWithArguments(t *testing.T) {
func TestMessageCommandArgumentsWithMalformedArguments(t *testing.T) {
message := tgbotapi.Message{Text: "/command-without argument space"}
message.Entities = &[]tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
message.Entities = []tgbotapi.MessageEntity{{Type: "bot_command", Offset: 0, Length: 8}}
if message.CommandArguments() != "without argument space" {
t.Fail()
}