gin icon indicating copy to clipboard operation
gin copied to clipboard

session存储数组/切片/map时,在当前也没有问题,其他页面会nil

Open langzishen opened this issue 1 year ago • 2 comments

当使用session存储数组/切片/map数据类型是,在其他页面取出时会为nil,并且在没有报错的情况下导致其他后存入session的值也存储失败,全部都时nil,请看下图:

00 1-1 2-2 2-1 1-2

langzishen avatar Aug 01 '22 07:08 langzishen

please english

qiuyuyin avatar Aug 13 '22 11:08 qiuyuyin

When you want to save the cookie value as type map[string]string by the method func (s *session) Save() will return err like "gob: type not registered for interface: map[string]string".

Because the package "github.com/gin-contrib/sessions" uses the "encoding/gob" by default. You have to register your type beforehand by using gob.Register(map[string]string{}).

Chasing1020 avatar Aug 23 '22 15:08 Chasing1020