草庐IT

Gorilla3D

全部标签

go - 使用 Gorilla MUX 和 Negroni 的子路由中间件

我试图只在某些路由上添加中间件。我写了这段代码:funcmain(){router:=mux.NewRouter().StrictSlash(false)admin_subrouter:=router.PathPrefix("/admin").Subrouter()//handlers.CombinedLoggingHandlercomesfromgorilla/handlersrouter.PathPrefix("/admin").Handler(negroni.New(negroni.Wrap(handlers.CombinedLoggingHandler(os.Stdout,ad

Golang Gorilla CEX.IO Websocket 认证错误

我目前正在尝试连接到CEX.IO比特币交易所的websocket。Websocket连接正常,但在身份验证时出现错误:Timestampisnotin20secrange。我不知道这是什么错误。createSignature的测试用例1和2正常(https://cex.io/websocket-api#authentication)。认证代码:functoHmac256(messagestring,secretstring)string{key:=[]byte(secret)h:=hmac.New(sha256.New,key)h.Write([]byte(message))retur

go - Gorilla mux 路由器不提供静态内容——比如 style.css、script.js

我是Go语言的初学者。我试图用GorrilaMux路由器提供静态容器。但是css和js不是我的服务器。projectf-mymux.god-pagesf-home.htmlf-about.htmld-publicd-cssf-style.cssd-jsf-script.js注意:f-文件&d-目录我的GO代码如下:packagemainimport("bufio""github.com/gorilla/mux""log""net/http""os""strings""text/template")funcmain(){serverWeb()}varstaticPages=populat

go - 如何在 gorilla/mux 包中初始化 HandleFunc 中的变量

我有一个处理函数:r.HandleFunc("/getstatus_a/{price}",getStatusWithPrice).Methods("GET")price是int变量,我需要在路径中初始化它。我该怎么做?附言在getStatusWithPrice()price中用作在sql请求中传输的参数。 最佳答案 问题解决了vars:=mux.Vars(r)price:=vars["price"] 关于go-如何在gorilla/mux包中初始化HandleFunc中的变量,我们在St

rest - golang gorilla/mux 和 rest GET 问题

我的删除处理程序:(我正在使用“github.com/gorilla/mux”)funcDeletePerson(whttp.ResponseWriter,r*http.Request){params:=mux.Vars(r)item:=params["id"]fmt.Println("Item=",item)...当被以下curl命令调用时返回Item="2":curl-XDELETEhttp://localhost:8000/address/2但是,我的测试代码:funcTestDeletePerson(t*testing.T){person:=&Person{UniqID:"2"

gorilla /websocket 设置读取限制?

//SetReadLimitsetsthemaximumsizeforamessagereadfromthepeer.Ifa//messageexceedsthelimit,theconnectionsendsaclosemessagetothepeer//andreturnsErrReadLimittotheapplication.func(c*Conn)SetReadLimit(limitint64){c.readLimit=limit}极限的单位是什么?知识库?MB? 最佳答案 基于gorilla/websocket的来源,以

go - 无法使用 Golang 从带有 mySQL 后端的 gorilla / session 中获取值(value)

我试图在使用mySQL后端的gorillasession中为我的模型保存一个结构,但当我尝试检索它时,venueID只得到0。我可以毫不费力地保存和获取即显消息。我的目标是在session中保存模型结构并检索它以获取编辑、更新和删除功能中的ID号。这是我的代码:typeappResourcestruct{tmpl*template.Template//net/httpstore*mysqlstore.MySQLStoredb*sql.DB//database/sql}//newAppResourcefunctiontopassglobalvarfuncnewAppResource(st

go - 如何使用 Gorilla 指定 WS ping 的频率

WebSocketRFC指出有用于ping/pong的控制帧。为了避免将应用程序代码编写为保活机制,是否可以使用GorillaWebSockets指定ping的频率? 最佳答案 因为应用程序负责使用GorillaWebSocket包发送ping,所以应用程序可以完全控制发送ping的频率。参见chatexample有关如何发送ping并使用它们检测死连接或卡住连接的示例。 关于go-如何使用Gorilla指定WSping的频率,我们在StackOverflow上找到一个类似的问题:

go - 将 Websocket 消息发送到 Go 中的特定 channel (使用 Gorilla)

我是Go的新手,发现自己将使用套接字作为我的第一个项目。这是一个多余的问题,但我无法理解如何将websocket更新发送到Go中的特定channel(使用Gorilla)。我正在使用codesamplefromthislink这个方法。但是修改发送消息到指定channel失败。这是我的示例代码ma​​in.gofuncmain(){flag.Parse()hub:=newHub()gohub.run()http.HandleFunc("/ws",func(whttp.ResponseWriter,r*http.Request){fmt.Println(hub)serveWs(hub,w

go - Gorilla xmlrpc 的小写方法

我正在使用GorillaXMLRPC.根据示例,func(h*HelloService)Say(r*http.Request,args*struct{Whostring},reply*struct{Messagestring})error{reply.Message="Hello,"+args.Who+"!"returnnil}和RPC.RegisterService(new(HelloService),"")给我一个服务HelloService.Say()。我想要helloService.say()。我能够通过将注册函数修改为RPC.RegisterService(new(Hello