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

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

Comment From: qiuyuyin

please english

Comment From: Chasing1020

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{}).