Good afternoon, I use sessions from here.
"github.com/gorilla/sessions" WbSocket "code.google.com/p/go.net/websocket"
At first I created a session, as it is written on the office. This option works:
session, _ := store.Get(r, "SessionId") // r- Request log.Println("Значение из сессии Id=", session.Values["Id"], " и FIO=", session.Values["FIO"])
It is necessary to work with this data and I save them ... But this option does not work
var ActiveClients = make(map[int ] ClientConn) type ClientConn struct { websocket *websocket.Conn Socket_Id int User_Id string FIO string Role string } func SockServer(ws *websocket.Conn) { session, _ := store.Get(r, "SessionId") Id =session.Values["Id"] FIO =string(session.Values["FIO"]) Role =session.Values["Role"] sockCli := ClientConn{ws, Soc_Id,Id,FIO,Role} ActiveClients[Soc_Id] = sockCli log.Println("Клиент подключился сокет=", Soc_Id, ".id- ", Id, " ФИО- ", FIO, " Роль- ", Role) }
Writes
cannot use Id (type interface {}) as type string in field value: need type assertion
here sockCli := ClientConn{ws, Soc_Id,Id,FIO,Role}
And for FIO
and Role
too, is the same. Why does it output the string
type to the console, and then it swears?
Update Thank you Vadim Shender, decided
Id , _ := session.Values["Id"].(string) FIO , _ := session.Values["FIO"].(string) Role , _ := session.Values["Role"].(string)