pyList

JSON and struct composition in Go

JSON and struct composition in Go

http://attilaolah.eu/2014/09/10/json-and-struct-composition-in-go/ 1

complexity: adds lots of extra code for big structs
复杂性:增加了许多额外的大结构代码
memory usage: must be careful not to do needless allocations
内存使用:一定要小心,不要做不必要的分配
type BlogPost struct {
    URL   string `json:"url"`
    Title string `json:"title"`
}

type Analytics struct {
    Visitors  int `json:"visitors"`
    PageViews int `json:"page_views"`
}

json.Marshal(struct{
    *BlogPost
    *Analytics
}{post, analytics})
本文标签: golang JSON struct
相关推荐
本文网址: https://pylist.com/t/1434021952 (转载注明出处)
如果你有任何建议或疑问可以在下面 留言
发表第一条评论!
验证码图片