草庐IT

private_method

全部标签

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 - 如何访问云构建器中的私有(private) Github 存储库?

我在Github上有两个私有(private)仓库,A和B,都是Golang项目。项目A依赖于存储库B。我已将这两个存储库链接到Google源代码并同意权限。云构建.yaml-name:'gcr.io/cloud-builders/git'args:['clone','https://source.developers.google.com/p/$PROJECT_ID/r/B']来自容器构建器的日志StartingStep#0Step#0:Alreadyhaveimage(withdigest):gcr.io/cloud-builders/gitStep#0:Cloninginto'B

google-app-engine - 如何使用 go 模块在 GAE SE Go 1.11 上导入私有(private)存储库?

我在github上有一个go库包仓库作为私有(private)仓库。我写了一个像下面这样的项目来导入上面的库包。packagemainimport"github.com/foo/libpackage"funcmain(){:}这是目录层次结构。path/to/project|-main.go|-go.mod`-go.sum部署时出现错误,无法解决go:github.com/foo/libpackage@v0.0.0-20181127123728-008fddddc190:gitfetch-foriginrefs/heads/*:refs/heads/*refs/tags/*:refs/

macos - Intellij IDEA (Golang) 使用/private/var/folders/

我的Goland运行程序(运行/调试配置)在os.Args[0]中使用/private/var/folders/7b/50mzg8x17q55rxfg3b0kpj88xcm2lx/T。我知道os.Args[0]是我程序的路径,但我可以将os.Args[0]作为我在Golandrunner中的工作目录吗?附言编辑配置中的工作目录设置正确 最佳答案 Iknowthatos.Args[0]isthepathtomyprogram,butcanIdoos.Args[0]tobemyworkingdirectoryinGolandrunner

methods - Go:方法调用后对象不持久

我正在尝试为我正在编写的程序实现MarshalBinary和UnmarshalBinary,但在调用UnmarshalBinary后,我的更改似乎并没有持续存在。我的MWE:packagemainimport("encoding/binary""fmt""strconv")typeteststruct{var1uint32var2uint32}func(selftest)MarshalBinary()([]byte,error){tmp:=make([]byte,8)binary.BigEndian.PutUint32(tmp[0:4],self.var1)binary.BigEndi

google-app-engine - GAE Go - 如何将私有(private)变量放入数据存储区?

我正在编写GoogleAppEngineGolang应用程序。我想要一个带有私有(private)变量的struct,这些变量只能通过适当的函数设置,例如:typeFoostruct{barstring}func(f*Foo)SetBar(bstring){f.bar="BAR:"+b}我希望能够将此数据保存在数据存储区中。但是,数据存储区似乎没有保存私有(private)变量。如何在数据存储中存储私有(private)变量? 最佳答案 如果你的类型实现了PropertyLoadSaverinterface就可以:func(f*Fo

go - 文本/模板 : "can' t call method/function with 0 results. "

如何在不返回任何值的模板中执行函数?这是示例:funcmain(){u,err:=url.Parse("http://example.com/test?param1=true¶m2=true")iferr!=nil{log.Fatal(err)}m:=u.Query()m.Del("param1")//param1successfuldeleted!u.RawQuery=m.Encode()fmt.Println(u.RawQuery)consttmpl=`{{$m:=.Query}}{{$m.Del"param2"}}{{.RawQuery}}`t:=template.Mus