Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
1530e3fb
authored
2013-01-01 23:11:15 +0800
by
xiemengjun
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add session support
1 parent
1f67fcb0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
beego.go
controller.go
beego.go
View file @
1530e3f
...
...
@@ -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 @
1530e3f
...
...
@@ -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
Styling with
Markdown
is supported
Attach a file
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 post a comment