How to temporarily rename the field of struct by golang
This article mainly introduces how golang temporarily renamed struct field, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Field temporarily renamed struct
Type CacheItem struct {Key string `json: "key" `MaxAge int `json: "cacheAge" `Value Value `json: "cacheValue" `} json.Marshal (struct {* CacheItem / / Omit bad keys OmitMaxAge omit `json: "cacheAge,omitempty" `OmitValue omit `json: "cacheValue,omitempty"` / / Add nice keys MaxAge int `json: "max_age" `Value * Value `json: "value" `} {CacheItem: item, / / Set the int by value: MaxAge: item.MaxAge, / / Set the nested struct by reference, avoid making a copy: Value: & item.Value }) Thank you for reading this article carefully I hope the article "how to temporarily change the name of golang to struct" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!