I use lib github.com/ipfans/echo-session. I can save session when set array struct
This my code:
Save session
type StaffInfor struct {
Login_id string
Family_name_cc string
First_name_cc string
Family_name_kana string
First_name_kana string
Role_id int
Password string
Message_invalid []string
}
~~~
session := session.Default(c)
session.Set("test", listStaffInfor)// listStaffInfor is array struct StaffInfor
session.Save()
Get from session
session := session.Default(c)
fmt.Println(session.Get("test"))
Console result display empty
Library github.com/ipfans/echo-session
is using github.com/gorilla/sessions
internally.
Gorilla session object is serialised using the encoding/gob
package. So to store a complex datatype within a session you have to register your struct
.
type StaffInfor struct {
Login_id string
Family_name_cc string
First_name_cc string
Family_name_kana string
First_name_kana string
Role_id int
Password string
Message_invalid []string
}
type ListStaffInfor []StaffInfor
func init() {
gob.Register(&StaffInfor{})
gob.Register(&ListStaffInfor{})
}
Note: If you're using cookie based session, it is not advised to store large object into session, because you might hit cookie size limitation 4KB.