问题
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