从结构中删除字段,转换结构 [英] Remove a field from a struct, transform a struct

查看:59
本文介绍了从结构中删除字段,转换结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Google Drive API中,我得到一个结构类型文件.该结构几乎与我要插入BigQuery的结构相同.

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.

File结构包含一个"AppProperties";与BigQuery不兼容的字段:

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

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

因此,我希望得到的最终结果是相同的结构,但删除了AppProperties字段.因此,基本上,问题是如何从结构中删除字段".但这没有意义,因为结构值是可变的,但结构字段不是.至少这是我现在所了解的.

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.

我能想到的唯一解决方案是,复制File结构定义,并省略AppProperties字段,并将所有字段值移到上方.

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.

在Go中执行此操作的正确方法是什么?

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

推荐答案

唯一的方法是复制struct并为您省略不必要的字段,这很繁琐,但没有其他方法...

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

这篇关于从结构中删除字段,转换结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆