草庐IT

request_method

全部标签

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

pointers - 为什么 2 个不同的 http.Request 结构的 http.Request.URL.Host 的地址相同?

此代码是大型代码库中的独立示例,用于尝试复制错误。该程序运行时,&request.URL.Host和&request1.URL.Host的地址相同。为什么?据我了解,这是两种不同的结构,因此URL.Host不应具有相同的地址。packagemainimport("crypto/tls""fmt""net/http""net/url")funcmain(){hostname:="www.google.com"uri,err:=url.Parse("http://www.google.com/")iferr!=nil{panic(err)}vartlsConfig*tls.Configtl

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")}然

json - 在 render.Bind 中置空 http.Request.Body

我正在使用github.com/pressly/chi构建这个简单的程序,我尝试从http.Request.Body中解码一些JSON:packagemainimport("encoding/json""fmt""net/http""github.com/pressly/chi""github.com/pressly/chi/render")typeTeststruct{Namestring`json:"name"`}func(p*Test)Bind(r*http.Request)error{err:=json.NewDecoder(r.Body).Decode(p)iferr!=ni

go - 错误 : invalid_request Missing required parameter: client_id in golang

我在使用GoogleOAuth2进行身份验证时遇到困难。我从谷歌开发者控制台获得了客户端ID和密码,我想出了这段代码:packagemainimport("fmt""golang.org/x/oauth2""golang.org/x/oauth2/google""io/ioutil""net/http""os")consthtmlIndex=`LoginwithGoogle`funcinit(){//SetupGoogle'sexampletestkeysos.Setenv("CLIENT_ID","somrestring-otherstring.apps.googleusercont

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 - gin-gonic 将 request.body 值映射到结构中

我是GO编程语言的新手。我正在使用gin-gonic框架构建Web服务器。我正在尝试将req.body中的值映射到一个结构上。我使用Postman在x-www-form-urlencoded下发送带有以下键/值的POST请求角色:管理员用户名:管理员用户名编号:1我的go代码如下packagejwtsecuritytokenimport("fmt""github.com/gin-gonic/gin")typerequestBodystruct{rolestringusernamestringidstring}funcGenerateToken(c*gin.Context){fmt.Pr