1. 首页
  2. 主题
  3. Go基础

如何初始化

zjako · · 2770 次点击
有结构体如下: ```go type NewsArticle struct { Title string `json:"title,omitempty"` // 图文消息标题 Description string `json:"description,omitempty"` // 图文消息描述 URL string `json:"url,omitempty"` // 点击后跳转的链接。 PicURL string `json:"picurl,omitempty"` // 图文消息的图片链接, } const NewsArticleCountLimit = 10 // News 消息, 注意沒有 Safe 字段. type News struct { CommonMessageHeader News struct { Articles []NewsArticle `json:"articles,omitempty"` // 图文消息,一个图文消息支持1到10条图文 } `json:"news"` } ``` 请问如何初始化news这个结构体,主要是articles不知道怎么初始化?
真是谢了,可以了
#2
更多评论
就正常 slice 初始化呗。比如 []NewsArticle{ NewsArticle{xxxx}, NewsArticle{xxxx}, } 这里提醒一下,此处最好使用 *NewArticle 而不是 NewArticle
#1

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中