草庐IT

non-struct

全部标签

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)”这本身是显而易见的。这对我来说是完全错误的方法还是有一个简单的解决方法如何让编译器“相信”传递的结构在运

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

go - 如何使用 struct 作为映射的替代品?

我阅读了CalebDoxsey的“GO编程简介”。在第6章中,他有以下示例:packagemainimport"fmt"funcmain(){elements:=map[string]map[string]string{"H":map[string]string{"name":"Hydrogen","state":"gas",},"He":map[string]string{"name":"Helium","state":"gas",},"Li":map[string]string{"name":"Lithium","state":"solid",},"Be":map[string]s

go - 如何使用 struct 作为映射的替代品?

我阅读了CalebDoxsey的“GO编程简介”。在第6章中,他有以下示例:packagemainimport"fmt"funcmain(){elements:=map[string]map[string]string{"H":map[string]string{"name":"Hydrogen","state":"gas",},"He":map[string]string{"name":"Helium","state":"gas",},"Li":map[string]string{"name":"Lithium","state":"solid",},"Be":map[string]s

arrays - 为什么不能超过 *[]Struct?

http://play.golang.org/p/jdWZ9boyrh我收到这个错误prog.go:29:invalidreceivertype*[]Sentence([]Sentenceisanunnamedtype)prog.go:30:cannotrangeoverS(type*[]Sentence)[processexitedwithnon-zerostatus]当我的函数尝试接收结构数组时。未命名类型是什么意思?为什么不能取名?我可以在函数外命名它,也可以将它们作为参数传递给它们。它不起作用。所以我只是将[]Sentence作为参数传递并解决了我需要解决的问题。但是当将它们作

arrays - 为什么不能超过 *[]Struct?

http://play.golang.org/p/jdWZ9boyrh我收到这个错误prog.go:29:invalidreceivertype*[]Sentence([]Sentenceisanunnamedtype)prog.go:30:cannotrangeoverS(type*[]Sentence)[processexitedwithnon-zerostatus]当我的函数尝试接收结构数组时。未命名类型是什么意思?为什么不能取名?我可以在函数外命名它,也可以将它们作为参数传递给它们。它不起作用。所以我只是将[]Sentence作为参数传递并解决了我需要解决的问题。但是当将它们作

去构建错误 : no non-test Go files in <dir>

尝试运行时出错gobuild./...来self的$GOPATH/src。nonon-testGofilesin错误是正确的中没有测试文件但为什么会导致编译错误?是错误吗? 最佳答案 称其为错误……如果测试通过,构建应该不会失败。归档于此:https://github.com/golang/go/issues/22409我提交的错误是https://github.com/golang/go/issues/8279的副本看起来它在1.3中被破坏了。 关于去构建错误:nonon-testGo

去构建错误 : no non-test Go files in <dir>

尝试运行时出错gobuild./...来self的$GOPATH/src。nonon-testGofilesin错误是正确的中没有测试文件但为什么会导致编译错误?是错误吗? 最佳答案 称其为错误……如果测试通过,构建应该不会失败。归档于此:https://github.com/golang/go/issues/22409我提交的错误是https://github.com/golang/go/issues/8279的副本看起来它在1.3中被破坏了。 关于去构建错误:nonon-testGo