I am using this library in golang to connect to socket server.https://github.com/hesh915/go-socket.io-client I have to pass an auth object as server is expecting an object which will authenticate the user, but in this implementation, query seems to take map as a parameter. I get an EOF error while sending the stringified struct to Query as given below:
opts.Query["auth"] = str
I have created a nested structure for that purpose, tried converting struct into byte data using marshal and type casted into string, passed it as key value pair to map but that didn't seem to work out. Here is how my auth nested struct looks like:
{"userInfo":{"id":"","username":"","permissionsInfo":{"permissions"["",""]}},"additionalInfo":""}
How to send this information with the implementation given below:
opts := &socketio_client.Options{
Transport: "websocket",
Query: make(map[string]string),
}
opts.Query["user"] = "user"
opts.Query["pwd"] = "pass"
uri := "http://192.168.1.70:9090/socket.io/"
I have provided the link to the library.
Minimal Reproducible Example
type User struct {
Userinfo UserInfo `json:"userInfo"`
AdditionalInfo string `json:"additionalInfo"`
}
type UserInfo struct {
Id string `json:"id"`
Username string `json:"username"`
Permissionsinfo PermissionsInfo `json:"permissionInfo"`
}
type PermissionsInfo struct {
Permissions []string `json:"permissions"`
}
func main() {
user := &User{
Userinfo: UserInfo{
Id: "",
Username: "",
Permissionsinfo: PermissionsInfo{
Permissions: []string{"", ""},
}},
AdditionalInfo: "",
}
b, _ := json.Marshal(user)
fmt.Println(string(b))
opts := &socketio_client.Options{
Transport: "websocket",
Query: make(map[string]string),
}
opts.Query["auth"] = string(b)
uri := origin + "/socket.io"
client, err := socketio_client.NewClient(uri, opts)
if err != nil {
if err == io.EOF {
fmt.Printf("NewClient error:%v\n", err)
return
}
return
}
client.On("error", func() {
fmt.Println("on error")
})
}
The error to the above code, that i'm getting:
NewClient error EOF
My server end has to receive the auth params as socket.handshake.auth
and that's understandable because the above functionality doesn't supports for auth
instead it does for query
. How can I achieve this functionality? Any help would be appreciated.