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
d835b0c8
Commit
d835b0c8
authored
Nov 01, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #235
parent
bc862e52
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
0 deletions
+54
-0
sess_file.go
session/sess_file.go
+28
-0
sess_mem.go
session/sess_mem.go
+4
-0
sess_mysql.go
session/sess_mysql.go
+11
-0
sess_redis.go
session/sess_redis.go
+6
-0
session.go
session/session.go
+5
-0
No files found.
session/sess_file.go
View file @
d835b0c8
...
...
@@ -2,6 +2,7 @@ package session
import
(
"errors"
"fmt"
"io"
"io/ioutil"
"os"
...
...
@@ -131,6 +132,18 @@ func (fp *FileProvider) SessionGC() {
filepath
.
Walk
(
fp
.
savePath
,
gcpath
)
}
func
(
fp
*
FileProvider
)
SessionAll
()
int
{
a
:=
&
activeSession
{}
err
:=
filepath
.
Walk
(
fp
.
savePath
,
func
(
path
string
,
f
os
.
FileInfo
,
err
error
)
error
{
return
a
.
visit
(
path
,
f
,
err
)
})
if
err
!=
nil
{
fmt
.
Printf
(
"filepath.Walk() returned %v
\n
"
,
err
)
return
0
}
return
a
.
total
}
func
(
fp
*
FileProvider
)
SessionRegenerate
(
oldsid
,
sid
string
)
(
SessionStore
,
error
)
{
err
:=
os
.
MkdirAll
(
path
.
Join
(
fp
.
savePath
,
string
(
oldsid
[
0
]),
string
(
oldsid
[
1
])),
0777
)
if
err
!=
nil
{
...
...
@@ -193,6 +206,21 @@ func gcpath(path string, info os.FileInfo, err error) error {
return
nil
}
type
activeSession
struct
{
total
int
}
func
(
self
*
activeSession
)
visit
(
paths
string
,
f
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
{
return
err
}
if
f
.
IsDir
()
{
return
nil
}
self
.
total
=
self
.
total
+
1
return
nil
}
func
init
()
{
Register
(
"file"
,
filepder
)
}
session/sess_mem.go
View file @
d835b0c8
...
...
@@ -142,6 +142,10 @@ func (pder *MemProvider) SessionGC() {
pder
.
lock
.
RUnlock
()
}
func
(
pder
*
MemProvider
)
SessionAll
()
int
{
return
pder
.
list
.
Len
()
}
func
(
pder
*
MemProvider
)
SessionUpdate
(
sid
string
)
error
{
pder
.
lock
.
Lock
()
defer
pder
.
lock
.
Unlock
()
...
...
session/sess_mysql.go
View file @
d835b0c8
...
...
@@ -152,6 +152,17 @@ func (mp *MysqlProvider) SessionGC() {
return
}
func
(
mp
*
MysqlProvider
)
SessionAll
()
int
{
c
:=
mp
.
connectInit
()
defer
c
.
Close
()
var
total
int
err
:=
c
.
QueryRow
(
"SELECT count(*) as num from session"
)
.
Scan
(
&
total
)
if
err
!=
nil
{
return
0
}
return
total
}
func
init
()
{
Register
(
"mysql"
,
mysqlpder
)
}
session/sess_redis.go
View file @
d835b0c8
...
...
@@ -128,6 +128,12 @@ func (rp *RedisProvider) SessionGC() {
return
}
//@todo
func
(
rp
*
RedisProvider
)
SessionAll
()
int
{
return
0
}
func
init
()
{
Register
(
"redis"
,
redispder
)
}
session/session.go
View file @
d835b0c8
...
...
@@ -27,6 +27,7 @@ type Provider interface {
SessionRead
(
sid
string
)
(
SessionStore
,
error
)
SessionRegenerate
(
oldsid
,
sid
string
)
(
SessionStore
,
error
)
SessionDestroy
(
sid
string
)
error
SessionAll
()
int
//get all active session
SessionGC
()
}
...
...
@@ -195,6 +196,10 @@ func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Reque
return
}
func
(
manager
*
Manager
)
GetActiveSession
()
int
{
return
manager
.
provider
.
SessionAll
()
}
//remote_addr cruunixnano randdata
func
(
manager
*
Manager
)
sessionId
(
r
*
http
.
Request
)
(
sid
string
)
{
...
...
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