草庐IT

METHOD_NAME

全部标签

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 - {{template "name"pipeline}} 是什么意思

这个问题在这里已经有了答案:Golangtemplateenginepipelines(1个回答)关闭4年前。在https://golang.org/pkg/text/template/#hdr-Actions,有如下解释{{template"name"pipeline}}Thetemplatewiththespecifiednameisexecutedwithdotsettothevalueofthepipeline.这是什么意思?什么是点?例如,我看到下面的模板代码——{{define"header"}}{{template"top".}}{{template"needs"}}..

go - Route53 : query domain records by Domain Name

使用Go和AWS-SDK我正在尝试查询AWS控制台中Route53->HostedZones下列出的route53CNAME和A记录。我可以使用以下代码进行查询,但它需要我必须提前知道的(神秘的)HostedZoneId。是否有不同的功能,或基于域名(例如XXX.XXX.com)的HostedZoneId查找?AWSLogin(instance)svc:=route53.New(instance.AWSSession)listParams:=&route53.ListResourceRecordSetsInput{HostedZoneId:aws.String("Z2798GPJN9C

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

function - 戈朗 : Stack multiple method calls on one line

Go入门。我正在尝试编写一个函数,该函数将第一个名字命名为首字母,然后将第二个命名为首字母。为什么我不能像下面这样堆叠方法调用?(之所以要在前面放一个.ToLower,是因为.Title只把第一个字母大写,其余的不变)packagemainimport("fmt""strings")funcmain(){firstName:="mElVIn"lastName:="themelvINATor"fmt.Println(nameCap(firstName,lastName))}funcnameCap(s1,s2string)(str1,str2string){s1=strings.ToLow

去建立错误 "db.GetUsers undefined (type *gorm.DB has no field or method GetUsers)"

我是golang的新手,正在尝试使用gin+gorm制作API服务器。我尝试构建下面的代码,但出现了type*gorm.DBhasnofieldormethodGetUsers错误。这是一个非常简单的API服务器,我只想从users表中获取所有用户。packagemodelsimport("github.com/jinzhu/gorm"_"github.com/jinzhu/gorm/dialects/postgres")vardb*gorm.DBfuncinit(){varerrerrordb,err=gorm.Open("postgres","host=localhostdbnam

Go : Same name and content struct in one package , 哪个将被初始化

有一个名为mount的包,它有两个相同的名称和内容结构mount_linxu.gopackagemountimport"fmt"typeMounterstruct{}func(mounter*Mounter)DoMount(pathstring)(bool,error){fmt.Printf("thisislinux")returntrue,nil}mount_mac.gopackagemountimport"fmt"typeMounterstruct{}func(mounter*Mounter)DoMount(pathstring)(bool,error){fmt.Printf("t