Get the App
SLTechnology News&Howtos  ›  Development  › 

How to temporarily rename the field of struct by golang

Shulou Source: shulou.com Published: 2022-06-01 04:10:39 09月22日 Update

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!

Tags: Articles fields value interest at the same time more friends knowledge editing industry information information channels channels reference learning help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple Shulou Tech Info NVidia Shulou Technology