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
1530e3fb
Commit
1530e3fb
authored
Jan 01, 2013
by
xiemengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add session support
parent
1f67fcb0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
+45
-0
beego.go
beego.go
+39
-0
controller.go
controller.go
+6
-0
No files found.
beego.go
View file @
1530e3fb
...
...
@@ -2,9 +2,12 @@ package beego
import
(
"fmt"
"github.com/astaxie/session"
_
"github.com/astaxie/session/providers/memory"
"net/http"
"os"
"path"
"strconv"
)
var
(
...
...
@@ -20,6 +23,13 @@ var (
ViewsPath
string
RunMode
string
//"dev" or "prod"
AppConfig
*
Config
//related to session
SessionOn
bool
// wheather auto start session,default is false
SessionProvider
string
// default session provider memory
SessionName
string
// sessionName cookie's name
SessionGCMaxLifetime
int64
// session's gc maxlifetime
GlobalSessions
*
session
.
Manager
//GlobalSessions
)
func
init
()
{
...
...
@@ -38,6 +48,10 @@ func init() {
RecoverPanic
=
true
PprofOn
=
false
ViewsPath
=
"views"
SessionOn
=
false
SessionProvider
=
"memory"
SessionName
=
"beegosessionID"
SessionGCMaxLifetime
=
3600
}
else
{
HttpAddr
=
AppConfig
.
String
(
"httpaddr"
)
if
v
,
err
:=
AppConfig
.
Int
(
"httpport"
);
err
!=
nil
{
...
...
@@ -71,6 +85,27 @@ func init() {
}
else
{
ViewsPath
=
views
}
if
ar
,
err
:=
AppConfig
.
Bool
(
"sessionon"
);
err
!=
nil
{
SessionOn
=
false
}
else
{
SessionOn
=
ar
}
if
ar
:=
AppConfig
.
String
(
"sessionprovider"
);
ar
==
""
{
SessionProvider
=
"memory"
}
else
{
SessionProvider
=
ar
}
if
ar
:=
AppConfig
.
String
(
"sessionname"
);
ar
==
""
{
SessionName
=
"beegosessionID"
}
else
{
SessionName
=
ar
}
if
ar
,
err
:=
AppConfig
.
Int
(
"sessiongcmaxlifetime"
);
err
!=
nil
{
int64val
,
_
:=
strconv
.
ParseInt
(
strconv
.
Itoa
(
ar
),
10
,
64
)
SessionGCMaxLifetime
=
int64val
}
else
{
SessionGCMaxLifetime
=
3600
}
}
StaticDir
[
"/static"
]
=
"static"
...
...
@@ -158,5 +193,9 @@ func Run() {
BeeApp
.
RegisterController
(
`/debug/pprof`
,
&
ProfController
{})
BeeApp
.
RegisterController
(
`/debug/pprof/:pp([\w]+)`
,
&
ProfController
{})
}
if
SessionOn
{
GlobalSessions
,
_
=
session
.
NewManager
(
SessionProvider
,
SessionName
,
SessionGCMaxLifetime
)
go
GlobalSessions
.
GC
()
}
BeeApp
.
Run
()
}
controller.go
View file @
1530e3fb
...
...
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"encoding/xml"
"github.com/astaxie/session"
"html/template"
"io/ioutil"
"net/http"
...
...
@@ -151,3 +152,8 @@ func (c *Controller) Input() url.Values {
c
.
Ctx
.
Request
.
ParseForm
()
return
c
.
Ctx
.
Request
.
Form
}
func
(
c
*
Controller
)
StartSession
()
(
sess
session
.
Session
)
{
sess
=
GlobalSessions
.
SessionStart
(
c
.
Ctx
.
ResponseWriter
,
c
.
Ctx
.
Request
)
return
}
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