如何在Go中获取socket.io握手查询

huangapple go评论72阅读模式
英文:

How to get socket.io handshake query in Go

问题

我们使用go-socket.io来运行一个socket服务器,并且我们需要使用握手查询数据对用户进行身份验证。
node.js中,我们使用类似以下的代码:

authDataString = socket.handshake.query.authData;

我们需要在Go中做类似的操作。

英文:

We use the go-socket.io package to run a socket server and we need to authenticate users with handshake query data.
In node.js we used code like:

authDataString = socket.handshake.query.authData;

and we need to do something similar in Go.

答案1

得分: 2

你可以使用socketRequest字段,使用FormValue从请求URL中获取查询参数:

    log.Print(socket.Request().FormValue("foo"))
英文:

You can use the Request field of a socket to get query parameters from the request URL using FormValue:

    log.Print(socket.Request().FormValue("foo"))

huangapple
  • 本文由 发表于 2015年7月23日 16:00:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/31581434.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定