add session to context

This commit is contained in:
yong.an 2020-07-13 18:23:57 +08:00
parent 3fb2294415
commit f3ca093478
2 changed files with 3 additions and 4 deletions

View File

@ -42,6 +42,7 @@ var (
// enumerate all the context keys
var (
SessionIDKey = "__xorm_session_id"
SessionKey = "__xorm_session_key"
SessionShowSQLKey = "__xorm_show_sql"
)

View File

@ -101,10 +101,8 @@ func newSessionID() string {
func newSession(engine *Engine) *Session {
var ctx context.Context
var sessionID string
if engine.logSessionID {
sessionID = newSessionID()
ctx = context.WithValue(engine.defaultContext, log.SessionIDKey, sessionID)
ctx = context.WithValue(engine.defaultContext, log.SessionIDKey, newSessionID())
} else {
ctx = engine.defaultContext
}
@ -139,7 +137,7 @@ func newSession(engine *Engine) *Session {
sessionType: engineSession,
}
if engine.logSessionID {
session.ctx = context.WithValue(session.ctx, sessionID, session)
session.ctx = context.WithValue(session.ctx, log.SessionKey, session)
}
return session
}