草庐IT

six_or_none

全部标签

mongodb - Go 和 MongoDb 错误 : has no field or method

我是Golang的新手。在尝试从MongoDb查询结果中提取password时,出现以下错误:"./1.go:73:results.passwordundefined(type[]Personhasnofieldormethodpassword)"错误是由代码中的倒数第二行引起的。如何分离查询结果?代码:packagemainimport("fmt""html/template""log""net/http""reflect""gopkg.in/mgo.v2/bson""gopkg.in/mgo.v2")typeloginstruct{UserNamestringPasswordstr

Go- 为什么我的 For 循环会抛出 "Unexpected Semi-colon or New-line"?

我正在编写一个掷骰子函数。为了添加每个骰子的结果,我使用for循环添加到输出变量。但是,当我尝试构建时出现错误;syntaxerror:unexpectedsemicolonornewline,expecting{这是在初始化for循环的行上抛出的。这是我的代码:fori:=0;isi只是一个包含2个值的int数组,mt是我在导入math/rand时给它起的名字。 最佳答案 你的循环有几个问题:方括号的使用很奇怪。在类型定义之外,这些在slice/数组名称之后,例如x[i]将为您提供slicex的第i个元素。在循环体内没有对i的引用

pointers - panic : runtime error: invalid memory address or nil pointer dereference

我目前正在使用Go的Soundcloud包装器,我想打印用户的关注者,但这是我第一次遇到指针问题。构建错误后panic:runtimeerror:invalidmemoryaddressornilpointerdereference[signal0xbcode=0x1addr=0x10pc=0xc9c26]代码packagemainimport("fmt""github.com/njasm/gosoundcloud")funcmain(){//callbackurlisoptional-nilinexamples,_:=gosoundcloud.NewSoundcloudApi("Cl

json - 在 Go 中处理 "a single element or an array"JSON 属性的最佳方法是什么?

现在我们有一个JSONHTTP请求数据,它将是单个元素,例如{"data":{"id":1}}或者像{"data":[{"id":1},{"id":2}]}这样的元素数组.由于客户端无法更改实现,我们必须保留并接受此数据结构。目前我实现结构如下:typeRequeststruct{rawDatajson.RawMessage`json:"data"`Data*Data`json:"-"`DataList[]*Data`json:"-"`}然后首先将“数据”属性作为json.RawMessage解析为变量req,首先尝试解析为单个元素,如果失败则尝试解析为数组。iferr:=json.U

go - undefined <type float32 has no field or method sum> 错误。如何解决?

这是我的程序。当我运行它时,它给出了以下错误-a.sumundefined(typefloat32hasnofieldormethodsum)packagemainimport("fmt")typeCalculationinterface{operation(input[]float32)}typeAdditionstruct{sumfloat32}func(aAddition)operation(input[]float32){a.sum=input[0]for_,a:=rangeinput[1:]{a.sum+=a}fmt.Println("Sum:",a.sum)}funcmai

Golang (v1.8) - 错误 : type *mux. Route has no field or method Method

我有一个配备了gorilla工具包的go/golang应用程序。我正在尝试使用gorilla/mux包进行路由。我的路线和错误信息如下。有什么指点吗?路线`r:=mux.NewRouter()r.HandleFunc("/",landing)r.HandleFunc("/contact",contact)r.HandleFunc("/faq",faq)r.HandleFunc("/register",accountsC.New).Method("GET")r.HandleFunc("/register",accountsC.Create).Method("POST")http.List

go - 是否有可能触发 "invalid memory address or nil pointer dereference"的错误?

我有一个偶尔会崩溃的应用程序:panic:运行时错误:无效的内存地址或零指针取消引用[信号SIGSEGV:分段违规代码=0x1地址=0x20pc=0x122e64a]跟踪一直导致返回语句,该语句返回一个结构和错误。新(“一些用于调试的文本:”+err.Error())该结构似乎没有任何可以取消引用指针的内容,但我重构了该函数,因此它使用了按引用传递并且不需要返回该函数;它只返回了errors.New()。panic还是发生了。我检查了函数并对其进行了更改,因此它只返回错误,没有错误。New()字符串加上err.Error()。现在我似乎不能再引起panic了……所以问题是:关于erro

sqlite - 运行时错误 : invalid memory address or nil pointer dereference when Querying

我一直在研究用于身份验证的API,在尝试将其部署到服务器时,我偶然发现了这个奇怪的错误。该代码在我的笔记本电脑上运行得非常好,但是当我尝试部署它时,出现了这个错误:PANIC:runtimeerror:invalidmemoryaddressornilpointerdereferencegoroutine21[running]:github.com/urfave/negroni.(*Recovery).ServeHTTP.func1(0x7f5771b811e8,0xc4200980e8,0xc42009a870,0xc420138800)/home/linux/go/src/gith

go - 程序在主程序 block 中发现错误后出现 panic 。 panic : runtime error: invalid memory address or nil pointer dereference

我是golang的新手。在定义位置后trycatch主block中的错误后,我的程序出现panic。我在某处读过,添加defer.close()可能会有所帮助,但编译器再次说你的结构中不存在这样的定义帮助我解决它。typeIPInfostruct{IPstringHostnamestringCitystringCountrystringLocstringOrgstringPostalstring}funcmain(){ip:=getLocalIpv4()location,err:=ForeignIP(ip)iferr!=nil{fmt.Println("errorbro")}fmt.P

go - 使用beego验证码: invalid memory address or nil pointer dereference

我想在Beego下使用captcha生成验证码。但是它有错误无效的内存地址或零指针取消引用。有谁知道如何解决这个问题?谢谢。RequestMethod:GETRequestURL:/accounts/forgotpasswordRemoteAddr:127.0.0.1StackC:/Go/src/runtime/asm_amd64.s:573C:/Go/src/runtime/panic.go:505C:/Go/src/text/template/exec.go:137C:/Go/src/runtime/asm_amd64.s:573C:/Go/src/runtime/panic.go