sessions
sessions copied to clipboard
How to solve this err :gob: type not registered for interface: components.UserInfoInSession
I defined a struce like this:
type UserInfoInSession struct {
Uid uint64 json:"uid"
Address string json:"address"
}
then use the session/redis like this
userInfo := components.UserInfoInSession{
Uid: account.Uid,
Address: account.Address,
}
session := sessions.Default(ctx)
session.Set(sessionKey, userBasicInfo)
err := session.Save()
here throw a err :"gob: type not registered for interface: components.UserInfoInSession"
I found gob need to call a register func: gob.Register
Temply I use a json string instand,but how can I use the struct ?
Maybe this will help you. for NewStore
befor. look at this references
import "encoding/gob"
gob.Register(UserInfoInSession{})
end