Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
3300db83
Commit
3300db83
authored
Mar 24, 2016
by
youngsterxyf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
in `session` package, add a helpful variable `SLogger` to help subpackage logging information
parent
2362ca00
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
8 deletions
+31
-8
ledis_session.go
session/ledis/ledis_session.go
+1
-1
sess_mysql.go
session/mysql/sess_mysql.go
+8
-2
sess_file.go
session/sess_file.go
+5
-5
session.go
session/session.go
+17
-0
No files found.
session/ledis/ledis_session.go
View file @
3300db83
...
...
@@ -100,7 +100,7 @@ func (lp *Provider) SessionInit(maxlifetime int64, savePath string) error {
nowLedis
,
err
:=
ledis
.
Open
(
cfg
)
c
,
err
=
nowLedis
.
Select
(
lp
.
db
)
if
err
!=
nil
{
p
rintln
(
err
)
session
.
SLogger
.
P
rintln
(
err
)
return
nil
}
return
nil
...
...
session/mysql/sess_mysql.go
View file @
3300db83
// Copyright 2014 beego Author. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -111,11 +112,14 @@ func (st *SessionStore) SessionRelease(w http.ResponseWriter) {
defer
st
.
c
.
Close
()
b
,
err
:=
session
.
EncodeGob
(
st
.
values
)
if
err
!=
nil
{
session
.
SLogger
.
Println
(
err
)
return
}
st
.
c
.
Exec
(
"UPDATE "
+
TableName
+
" set `session_data`=?, `session_expiry`=? where session_key=?"
,
_
,
err
=
st
.
c
.
Exec
(
"UPDATE "
+
TableName
+
" set `session_data`=?, `session_expiry`=? where session_key=?"
,
b
,
time
.
Now
()
.
Unix
(),
st
.
sid
)
if
err
!=
nil
{
session
.
SLogger
.
Println
(
err
)
}
}
// Provider mysql session provider
...
...
@@ -128,6 +132,7 @@ type Provider struct {
func
(
mp
*
Provider
)
connectInit
()
*
sql
.
DB
{
db
,
e
:=
sql
.
Open
(
"mysql"
,
mp
.
savePath
)
if
e
!=
nil
{
session
.
SLogger
.
Println
(
e
)
return
nil
}
return
db
...
...
@@ -223,6 +228,7 @@ func (mp *Provider) SessionAll() int {
var
total
int
err
:=
c
.
QueryRow
(
"SELECT count(*) as num from "
+
TableName
)
.
Scan
(
&
total
)
if
err
!=
nil
{
session
.
SLogger
.
Println
(
err
)
return
0
}
return
total
...
...
session/sess_file.go
View file @
3300db83
...
...
@@ -16,7 +16,6 @@ package session
import
(
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
...
...
@@ -82,6 +81,7 @@ func (fs *FileSessionStore) SessionID() string {
func
(
fs
*
FileSessionStore
)
SessionRelease
(
w
http
.
ResponseWriter
)
{
b
,
err
:=
EncodeGob
(
fs
.
values
)
if
err
!=
nil
{
SLogger
.
Println
(
err
)
return
}
_
,
err
=
os
.
Stat
(
path
.
Join
(
filepder
.
savePath
,
string
(
fs
.
sid
[
0
]),
string
(
fs
.
sid
[
1
]),
fs
.
sid
))
...
...
@@ -123,7 +123,7 @@ func (fp *FileProvider) SessionRead(sid string) (Store, error) {
err
:=
os
.
MkdirAll
(
path
.
Join
(
fp
.
savePath
,
string
(
sid
[
0
]),
string
(
sid
[
1
])),
0777
)
if
err
!=
nil
{
p
rintln
(
err
.
Error
())
SLogger
.
P
rintln
(
err
.
Error
())
}
_
,
err
=
os
.
Stat
(
path
.
Join
(
fp
.
savePath
,
string
(
sid
[
0
]),
string
(
sid
[
1
]),
sid
))
var
f
*
os
.
File
...
...
@@ -191,7 +191,7 @@ func (fp *FileProvider) SessionAll() int {
return
a
.
visit
(
path
,
f
,
err
)
})
if
err
!=
nil
{
fmt
.
Printf
(
"filepath.Walk() returned %v
\n
"
,
err
)
SLogger
.
Printf
(
"filepath.Walk() returned %v
\n
"
,
err
)
return
0
}
return
a
.
total
...
...
@@ -205,11 +205,11 @@ func (fp *FileProvider) SessionRegenerate(oldsid, sid string) (Store, error) {
err
:=
os
.
MkdirAll
(
path
.
Join
(
fp
.
savePath
,
string
(
oldsid
[
0
]),
string
(
oldsid
[
1
])),
0777
)
if
err
!=
nil
{
p
rintln
(
err
.
Error
())
SLogger
.
P
rintln
(
err
.
Error
())
}
err
=
os
.
MkdirAll
(
path
.
Join
(
fp
.
savePath
,
string
(
sid
[
0
]),
string
(
sid
[
1
])),
0777
)
if
err
!=
nil
{
p
rintln
(
err
.
Error
())
SLogger
.
P
rintln
(
err
.
Error
())
}
_
,
err
=
os
.
Stat
(
path
.
Join
(
fp
.
savePath
,
string
(
sid
[
0
]),
string
(
sid
[
1
]),
sid
))
var
newf
*
os
.
File
...
...
session/session.go
View file @
3300db83
...
...
@@ -32,8 +32,11 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
"time"
)
...
...
@@ -61,6 +64,8 @@ type Provider interface {
var
provides
=
make
(
map
[
string
]
Provider
)
var
SLogger
=
newSessionLog
(
os
.
Stderr
)
// Register makes a session provide available by the provided name.
// If Register is called twice with the same name or if driver is nil,
// it panics.
...
...
@@ -296,3 +301,15 @@ func (manager *Manager) isSecure(req *http.Request) bool {
}
return
true
}
// Log implement the log.Logger
type
sessionLog
struct
{
*
log
.
Logger
}
// NewLog set io.Writer to create a Logger for session.
func
newSessionLog
(
out
io
.
Writer
)
*
sessionLog
{
sl
:=
new
(
sessionLog
)
sl
.
Logger
=
log
.
New
(
out
,
"[SESSION]"
,
1e9
)
return
sl
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment