sessions icon indicating copy to clipboard operation
sessions copied to clipboard

How to solve this err :gob: type not registered for interface: components.UserInfoInSession

Open minutel163 opened this issue 1 year ago • 1 comments

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 ?

minutel163 avatar Sep 08 '22 14:09 minutel163

Maybe this will help you. for NewStore befor. look at this references

import "encoding/gob"

gob.Register(UserInfoInSession{})

end

Guanghua0714 avatar Sep 14 '22 18:09 Guanghua0714