LINUX.ORG.RU

Сообщения Abzu

 

Заполнить структуру в Golang

Форум — Development

Доброго здравия всем!

Есть такая структура:

	type Bimbo struct {
		Messages []struct {
			Attachment struct {
				Type    string `json:"type"`
				Payload struct {
					TemplateType string `json:"template_type"`
					Text         string `json:"text"`
					Buttons      []struct {
						Type                string `json:"type"`
						URL                 string `json:"url"`
						Title               string `json:"title"`
						WebviewHeightRatio  string `json:"webview_height_ratio"`
						MessengerExtensions bool   `json:"messenger_extensions"`
					} `json:"buttons"`
				} `json:"payload"`
			} `json:"attachment"`
		} `json:"messages"`
	}

Как ее правильно заполнить? Если делать так:

input := new(Bimbo)
input.Messages[0].Attachment.Type = "sukaaa"

То получем закономерное - runtime error: index out of range

Что делать и как быть?

Спасибо!

 

Abzu
()

RSS подписка на новые темы