草庐IT

echo-request

全部标签

go - 如何在 Revel Controller 中获取 http.ResponseWriter 和 http.Request

我正在尝试实现一个oauth服务器,我正在使用的包需要完整的http.ResponseWriter和http.Request类型。c.Response不包含http.ResponseWriter包含的所有方法,并且c.Request给出错误类型不兼容。如何在RevelController中获取http.ResponseWriter和http.Request?typeclientstruct{ClientIdstringClientSecretstring}typeAppstruct{*revel.Controller}func(cApp)TokenRequest(){r:=c.Requ

go - 如何将 JWT 身份验证添加到 swagger (go + echo + swaggo/swag)

我正在使用swaggo(https://github.com/swaggo/swag)为我的API自动创建有效的swagger规范。swagger规范允许我运行所有API端点并接收响应。然后我将JWT身份验证添加到我的所有端点。现在我无法使用swagger规范来运行任何端点,因为它总是无法通过身份验证。我需要向每个端点添加哪些注释,以配置Swagger规范以允许传递JWT?我已经在https://github.com/swaggo/swag阅读了自述文件谷歌搜索无果。 最佳答案 似乎添加到每个端点的这些评论起到了作用......//

go - x/net/websocket 获取类似 *http.Request 的 cookie

我正在尝试获取一个cookie,就像*http.Request所做的那样(r.Cookie("cookie_key")),我如何在没有连接升级的情况下实现这一点(纯ws) 最佳答案 引用thiscommit,实际上你可以调用ws.Request().Cookie("guid") 关于go-x/net/websocket获取类似*http.Request的cookie,我们在StackOverflow上找到一个类似的问题: https://stackoverfl

google-app-engine - 谷歌应用引擎去 SDK : Request to '/' failed

我刚刚开始使用GAE,我在这里有以下指南https://developers.google.com/appengine/docs/go/gettingstarted/devenvironment和这里的一些helloword教程https://developers.google.com/appengine/docs/go/gettingstarted/helloworld.我的问题是当我输入goappserve时它起作用了。并像这样显示日志:INFO2014-05-1808:44:57,130devappserver2.py:765]SkippingSDKupdatecheck.WAR

go - 为什么 request.ParseForm() 耗尽 request.Body?

在此代码中,如果我对ParseForm()调用进行注释,请求将按预期工作packagemainimport("fmt""net/http""net/url""strings")funcmain(){v:=make(url.Values)v.Set("status","yeah!")request,error:=http.NewRequest("POST","http://httpbin.org/post",strings.NewReader(v.Encode()))iferror!=nil{fmt.Println(error)}request.Header.Set("Content-T

testing - echo c.Get ("user") 在测试环境中不起作用

我正在尝试测试基于echo框架/路由器构建的golangAPI。我有以下测试......funcTestLogout(t*testing.T){loadConfig()db:=stubDBs(t)Convey("Whenyoupostto/logout",t,func(){Convey("withavalidtoken,youshouldgetaasuccessmsgandbeloggedout",func(){e:=echo.New()e.Use(middleware.JWTWithConfig(middleware.JWTConfig{SigningKey:[]byte("secr

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

go - 如何使用 google/jsonapi 和 echo 框架返回有效的 jsonapi 响应

下面的代码返回两个连接的JSON字符串和一个错误的内容类型text/plain。应该是application/vnd.api+jsonpackagemainimport("github.com/google/jsonapi""github.com/labstack/echo""net/http")typeAlbumstruct{IDint`jsonapi:"primary,albums"`Namestring`jsonapi:"attr,name"`}funcmain(){e:=echo.New()e.GET("/",func(cecho.Context)error{jsonapi.M

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