Remove a field from a struct, transform a struct

守給你的承諾、 提交于 2021-01-29 09:41:59

问题


From the Google Drive API I get a struct type File. This struct is almost the same as the struct I would like to insert into BigQuery.

The File struct contains an "AppProperties" field that is incompatible with BigQuery:

AppProperties map[string]string `json:"appProperties,omitempty"`

So the end result that I would like to have is the same struct, with the AppProperties field removed. So basically the question is "how to remove a field from a struct" but that does not make sense as the struct values are mutable, but the struct fields are not. At least that is what I understand now.

The only solution I can think of is, copy the File struct definition and omit the AppProperties field and move all the field values over.

What would be the right way to do this in Go?


回答1:


The only way is to copy struct and omit needless field for you, it's tedious but there is no other way...



来源:https://stackoverflow.com/questions/65329591/remove-a-field-from-a-struct-transform-a-struct

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!