草庐IT

private_struct

全部标签

json - Golang 不能使用 as type struct array 或 slice literal

我正在尝试在Go中编写一个函数,该函数采用带有目录URL的JSON并执行BFS以查找该目录中的文件。当我找到一个作为目录的JSON时,代码会生成一个URL并且应该将该URL排入队列。当我尝试在循环中的append()中创建结构时,出现错误。typeContentResp[]struct{Namestring`json:"name"`ContentTypestring`json:"type"`DownloadURLstring`json:"download_url"`}...varcontentRespContentRespsearch(contentQuery,&contentResp

json - Golang 不能使用 as type struct array 或 slice literal

我正在尝试在Go中编写一个函数,该函数采用带有目录URL的JSON并执行BFS以查找该目录中的文件。当我找到一个作为目录的JSON时,代码会生成一个URL并且应该将该URL排入队列。当我尝试在循环中的append()中创建结构时,出现错误。typeContentResp[]struct{Namestring`json:"name"`ContentTypestring`json:"type"`DownloadURLstring`json:"download_url"`}...varcontentRespContentRespsearch(contentQuery,&contentResp

xml-parsing - Go 中的 DRY struct 标签

我正在解析XML,在文档的几乎每一层,都有一个描述。这是一个玩具示例:outerobjectfirstkindofsubobjectsomegoopsecondkindofsubobjectsomeothergoop这意味着涉及的每个结构都有一个相同的Description成员,带有相同的标记`xml:"description,omitempty"`。这是功能代码:http://play.golang.org/p/1-co6Qcm8d我宁愿描述标签是干的。想要做的显而易见的事情是:typeDescriptionstring`xml:"description,omitempty"`然后在

xml-parsing - Go 中的 DRY struct 标签

我正在解析XML,在文档的几乎每一层,都有一个描述。这是一个玩具示例:outerobjectfirstkindofsubobjectsomegoopsecondkindofsubobjectsomeothergoop这意味着涉及的每个结构都有一个相同的Description成员,带有相同的标记`xml:"description,omitempty"`。这是功能代码:http://play.golang.org/p/1-co6Qcm8d我宁愿描述标签是干的。想要做的显而易见的事情是:typeDescriptionstring`xml:"description,omitempty"`然后在

struct - 如何解决 "type interface has no field or method"错误?

我想为mgoAPI写一个抽象:packagemanagerimport"labix.org/v2/mgo"typeManagerstruct{collection*mgo.Collection}func(m*Manager)Update(modelinterface{})error{returnm.collection.UpdateId(model.Id,model)}编译时我得到“model.Idundefined(interface{}hasnofieldormethodId)”这本身是显而易见的。这对我来说是完全错误的方法还是有一个简单的解决方法如何让编译器“相信”传递的结构在运

struct - 如何解决 "type interface has no field or method"错误?

我想为mgoAPI写一个抽象:packagemanagerimport"labix.org/v2/mgo"typeManagerstruct{collection*mgo.Collection}func(m*Manager)Update(modelinterface{})error{returnm.collection.UpdateId(model.Id,model)}编译时我得到“model.Idundefined(interface{}hasnofieldormethodId)”这本身是显而易见的。这对我来说是完全错误的方法还是有一个简单的解决方法如何让编译器“相信”传递的结构在运

go - Go中嵌入式私有(private)接口(interface)的可见性

如果我将一个小写名称(私有(private))的接口(interface)嵌入到另一个大写名称(公共(public))的接口(interface)中,我假设定义包之外的代码看不到嵌入的私有(private)接口(interface)。这个假设是否正确?typebinterface{G()int}typeAinterface{F()stringb}定义包之外的代码无法“看到”嵌入的b,对吗?外部代码不能通过A的实例调用G。 最佳答案 在界面中嵌入未导出的界面接口(interface)嵌入接口(interface)无非就是合并metho

go - Go中嵌入式私有(private)接口(interface)的可见性

如果我将一个小写名称(私有(private))的接口(interface)嵌入到另一个大写名称(公共(public))的接口(interface)中,我假设定义包之外的代码看不到嵌入的私有(private)接口(interface)。这个假设是否正确?typebinterface{G()int}typeAinterface{F()stringb}定义包之外的代码无法“看到”嵌入的b,对吗?外部代码不能通过A的实例调用G。 最佳答案 在界面中嵌入未导出的界面接口(interface)嵌入接口(interface)无非就是合并metho

reflection - 在golang中使用reflect打印struct指针字段类型

我有一个结构,我正在尝试遍历所有字段以确定该字段是否为映射(或指向映射的指针)。对于非指针字段,我能够将字段类型与reflect.Map进行比较,但我在对指针字段执行相同操作时遇到了麻烦。如果该字段有一个值,我可以使用Elem()来确定指针字段类型,但如果该字段为nil,该方法将不起作用,我会得到“无效”。关于如何实现这一目标的任何想法?Playground在这里。packagemainimport("fmt""reflect")typeItemstruct{itemMapmap[string]interface{}itemMapPtr*map[string]interface{}}f

reflection - 在golang中使用reflect打印struct指针字段类型

我有一个结构,我正在尝试遍历所有字段以确定该字段是否为映射(或指向映射的指针)。对于非指针字段,我能够将字段类型与reflect.Map进行比较,但我在对指针字段执行相同操作时遇到了麻烦。如果该字段有一个值,我可以使用Elem()来确定指针字段类型,但如果该字段为nil,该方法将不起作用,我会得到“无效”。关于如何实现这一目标的任何想法?Playground在这里。packagemainimport("fmt""reflect")typeItemstruct{itemMapmap[string]interface{}itemMapPtr*map[string]interface{}}f