草庐IT

proto_method_implemented

全部标签

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

methods - Golang 方法参数接口(interface){}

代码:typeStringstruct{Resultstring}funcmain(){result:=&String{Result:"value"}//varteststring="value"//result:=&testtestDataBase(result)fmt.Print(result.Result)//expect:"34",but:"value"}functestDataBase(strinterface{}){strV,ok:=str.(String)ifok{strV.Result="34"}}那么,我怎样才能得到结果:34呢? 最佳答案

golang 练习 :images missing at method

我正在完成练习:图片位于https://tour.golang.org/methods/25我遇到了一个问题。这是我的代码...packagemainimport("golang.org/x/tour/pic""image")typeImagestruct{image*image.RGBA}funcmain(){rect:=image.Rect(0,0,255,255)myImage:=image.NewRGBA(rect)m:=Image{myImage}pic.ShowImage(m)}它给了我错误...tmp/sandbox089594299/main.go:16:cannotu

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

azure - 去 + azure : Calling a method return undefined

我正在尝试使用GoAzureSDK调用通知中心api我已经安装了SDK并导入到GO文件中:packagehubimport("fmt""github.com/Azure/azure-sdk-for-go/arm/notificationhubs")funcGetHub(){ifresourceType,err:=notificationhubs.Get("sourceGroupName","NameSpaceValue","NameOfTheHub");err!=nil{fmt.Println("Erroroccured")return}fmt.Println("Success")}然

google-app-engine - 谷歌应用引擎/啊/健康 "Method does not exist."

对projectname.appspot.com/_ah/health的请求返回以下错误{"code":5,"message":"Methoddoesnotexist.","details":[{"@type":"type.googleapis.com/google.rpc.DebugInfo","stackEntries":[],"detail":"service_control"}]}本地测试,效果很好。缩写的app.yaml:runtime:goenv:flexapi_version:go1app.go主要功能:funcmain(){r:=mux.NewRouter()r.Han

go - 在 golang 中导入 “google/protobuf/descriptor.proto”

我正在使用customoptions为我的原型(prototype)服务定义定义swagger注释。这个swaggerannotations已经有一个实现所以我只需要在我的.proto服务定义中导入这个实现import"protoc-gen-swagger/options/annotations.proto";...问题是这个库依赖于google/protobuf/descriptor.proto并且这个描述符库是根据proto2规范创建的(这个库来自protocolbuffers/protobufproject)syntax="proto2";packagegoogle.protob

go - 无法在ubuntu中为golang编译proto文件

我已经安装了这些包:google.golang.org/grpcgithub.com/golang/protobuf/protoc-gen-go导出路径如下:exportPATH=$PATH:/usr/local/go/bin当我尝试使用protoc命令编译proto文件时,我看到命令未找到错误:protoc--go_out=.helloworld/helloworld.protozsh:commandnotfound:protoc我的项目路径是这样的:/home/my-username/go/src/github.com/my-username/helloworld我的go版本:go

go - 使用 Go 模块时生成 in-repo protos 的最佳实践

tl;dr以前配置为使用GOPATH的repo现在配置为模块。一切都很好,越来越好。但是,protoc正确地(!)为在github.com/path/to/repo/protos结构中的repo中定义的protobufs生成Golang代码,而我现在更喜欢在我的源代码中生成这些代码,在GOPATH之外。我正在移动他们来解决这个问题。有更好的解决方案吗?我有一个GitHub存储库。为了方便讨论,我们称它为github.com/acme/toolbox。在子目录中,我有protobuf文件,其中包括:packageacme.toolbox.v1;optiongo_package="gith