sessions
sessions copied to clipboard
How do I get the sessionId
I want get like this session_K36NW244LA2GB23N2HEYVWGTERU2S52C7YNV3Q2SDQLF53SQLJIQ
it is hard to get the sessionId !!!
Can't you just read it from the client's cookie ?
You can only rewrite Session Strust by copy the old. copy all about the old and add func named SessionId().
type session struct { name string request *http.Request store sessions.Store session *sessions.Session written bool writer http.ResponseWriter } func (s *session) Session() *sessions.Session { if s.session == nil { var err error s.session, err = s.store.Get(s.request, s.name) if err != nil { log.Printf(errorFormat, err) } } return s.session } func (s *session) SessionId() string { return s.Session().ID }
You can only rewrite Session Strust by copy the old. copy all about the old and add func named SessionId().
type session struct { name string request *http.Request store sessions.Store session *sessions.Session written bool writer http.ResponseWriter } func (s *session) Session() *sessions.Session { if s.session == nil { var err error s.session, err = s.store.Get(s.request, s.name) if err != nil { log.Printf(errorFormat, err) } } return s.session } func (s *session) SessionId() string { return s.Session().ID }
but session struct is private
I want to set my session id (switch session) as well
Anyway to implement this?
Like the alternative of session_id($sess_id_1);
in php?
func (u *User) Test(c *gin.Context) {
session := sessions.Default(c)
session.Set("test", 123)
of := reflect.ValueOf(session).Elem()
realSession := of.FieldByName("session")
sessionId := realSession.Elem().FieldByName("ID")
//getid
log.Println(sessionId.String())
// setId
sessionPtr := reflect.NewAt(sessionId.Type(), unsafe.Pointer(sessionId.UnsafeAddr())).Elem()
sessionPtr.SetString("this_is_test")
// set cookie
session.Save()
}