mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 16:10:55 +00:00
not just export a variable
This commit is contained in:
parent
3300db832b
commit
56860d1fea
@ -100,7 +100,7 @@ func (lp *Provider) SessionInit(maxlifetime int64, savePath string) error {
|
|||||||
nowLedis, err := ledis.Open(cfg)
|
nowLedis, err := ledis.Open(cfg)
|
||||||
c, err = nowLedis.Select(lp.db)
|
c, err = nowLedis.Select(lp.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
session.SLogger.Println(err)
|
println(err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
// Copyright 2014 beego Author. All Rights Reserved.
|
// Copyright 2014 beego Author. All Rights Reserved.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -112,14 +111,10 @@ func (st *SessionStore) SessionRelease(w http.ResponseWriter) {
|
|||||||
defer st.c.Close()
|
defer st.c.Close()
|
||||||
b, err := session.EncodeGob(st.values)
|
b, err := session.EncodeGob(st.values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
session.SLogger.Println(err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = st.c.Exec("UPDATE "+TableName+" set `session_data`=?, `session_expiry`=? where session_key=?",
|
st.c.Exec("UPDATE "+TableName+" set `session_data`=?, `session_expiry`=? where session_key=?",
|
||||||
b, time.Now().Unix(), st.sid)
|
b, time.Now().Unix(), st.sid)
|
||||||
if err != nil {
|
|
||||||
session.SLogger.Println(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provider mysql session provider
|
// Provider mysql session provider
|
||||||
@ -132,7 +127,6 @@ type Provider struct {
|
|||||||
func (mp *Provider) connectInit() *sql.DB {
|
func (mp *Provider) connectInit() *sql.DB {
|
||||||
db, e := sql.Open("mysql", mp.savePath)
|
db, e := sql.Open("mysql", mp.savePath)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
session.SLogger.Println(e)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return db
|
return db
|
||||||
@ -228,7 +222,6 @@ func (mp *Provider) SessionAll() int {
|
|||||||
var total int
|
var total int
|
||||||
err := c.QueryRow("SELECT count(*) as num from " + TableName).Scan(&total)
|
err := c.QueryRow("SELECT count(*) as num from " + TableName).Scan(&total)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
session.SLogger.Println(err)
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return total
|
return total
|
||||||
|
@ -88,8 +88,10 @@ func (fs *FileSessionStore) SessionRelease(w http.ResponseWriter) {
|
|||||||
var f *os.File
|
var f *os.File
|
||||||
if err == nil {
|
if err == nil {
|
||||||
f, err = os.OpenFile(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid), os.O_RDWR, 0777)
|
f, err = os.OpenFile(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid), os.O_RDWR, 0777)
|
||||||
|
SLogger.Println(err)
|
||||||
} else if os.IsNotExist(err) {
|
} else if os.IsNotExist(err) {
|
||||||
f, err = os.Create(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid))
|
f, err = os.Create(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid))
|
||||||
|
SLogger.Println(err)
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,8 @@ type Provider interface {
|
|||||||
|
|
||||||
var provides = make(map[string]Provider)
|
var provides = make(map[string]Provider)
|
||||||
|
|
||||||
var SLogger = newSessionLog(os.Stderr)
|
// SLogger a helpful variable to log information about session
|
||||||
|
var SLogger = NewSessionLog(os.Stderr)
|
||||||
|
|
||||||
// Register makes a session provide available by the provided name.
|
// Register makes a session provide available by the provided name.
|
||||||
// If Register is called twice with the same name or if driver is nil,
|
// If Register is called twice with the same name or if driver is nil,
|
||||||
@ -303,13 +304,13 @@ func (manager *Manager) isSecure(req *http.Request) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Log implement the log.Logger
|
// Log implement the log.Logger
|
||||||
type sessionLog struct {
|
type Log struct {
|
||||||
*log.Logger
|
*log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLog set io.Writer to create a Logger for session.
|
// NewSessionLog set io.Writer to create a Logger for session.
|
||||||
func newSessionLog(out io.Writer) *sessionLog {
|
func NewSessionLog(out io.Writer) *Log {
|
||||||
sl := new(sessionLog)
|
sl := new(Log)
|
||||||
sl.Logger = log.New(out, "[SESSION]", 1e9)
|
sl.Logger = log.New(out, "[SESSION]", 1e9)
|
||||||
return sl
|
return sl
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user