Update session
This commit is contained in:
parent
f9c07c4186
commit
fd1831052c
|
@ -4,7 +4,6 @@ path=github.com/gogits/gogs
|
|||
[deps]
|
||||
github.com/codegangsta/cli=
|
||||
github.com/codegangsta/martini=
|
||||
github.com/martini-contrib/sessions=
|
||||
github.com/Unknwon/com=
|
||||
github.com/Unknwon/cae=
|
||||
github.com/Unknwon/goconfig=
|
||||
|
|
|
@ -43,7 +43,7 @@ There are two ways to install Gogs:
|
|||
## Acknowledgments
|
||||
|
||||
- Logo is inspired by [martini](https://github.com/martini-contrib).
|
||||
- Mail service is based on [WeTalk](https://github.com/beego/wetalk).
|
||||
- Mail Service is based on [WeTalk](https://github.com/beego/wetalk).
|
||||
- System Monitor Status is based on [GoBlog](https://github.com/fuxiaohei/goblog).
|
||||
|
||||
## Contributors
|
||||
|
|
25
conf/app.ini
25
conf/app.ini
|
@ -75,28 +75,25 @@ HOST =
|
|||
[session]
|
||||
; Either "memory", "file", "redis" or "mysql", default is "memory"
|
||||
PROVIDER = file
|
||||
; provider config
|
||||
; Provider config options
|
||||
; memory: not have any config yet
|
||||
; file: session file path
|
||||
; e.g. tmp/sessions
|
||||
; redis: config like redis server addr,poolSize,password
|
||||
; e.g. 127.0.0.1:6379,100,astaxie
|
||||
; mysql: go-sql-driver/mysql dsn config string
|
||||
; e.g. root:password@/session_table
|
||||
; file: session file path, e.g. data/sessions
|
||||
; redis: config like redis server addr, poolSize, password, e.g. 127.0.0.1:6379,100,astaxie
|
||||
; mysql: go-sql-driver/mysql dsn config string, e.g. root:password@/session_table
|
||||
PROVIDER_CONFIG = data/sessions
|
||||
; session cookie name
|
||||
; Session cookie name
|
||||
COOKIE_NAME = i_like_gogits
|
||||
; if you use session in https only, default is false
|
||||
; If you use session in https only, default is false
|
||||
COOKIE_SECURE = false
|
||||
; enable set cookie, default is true
|
||||
; Enable set cookie, default is true
|
||||
ENABLE_SET_COOKIE = true
|
||||
; session gc time interval, default is 86400
|
||||
; Session GC time interval, default is 86400
|
||||
GC_INTERVAL_TIME = 86400
|
||||
; session life time, default is 86400
|
||||
; Session life time, default is 86400
|
||||
SESSION_LIFE_TIME = 86400
|
||||
; session id hash func, default is sha1
|
||||
; Session id hash func, default is sha1
|
||||
SESSION_ID_HASHFUNC = sha1
|
||||
; session hash key, default is use random string
|
||||
; Session hash key, default is use random string
|
||||
SESSION_ID_HASHKEY =
|
||||
|
||||
[picture]
|
||||
|
|
2
gogs.go
2
gogs.go
|
@ -20,7 +20,7 @@ import (
|
|||
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
|
||||
const go12tag = true
|
||||
|
||||
const APP_VER = "0.1.5.0322"
|
||||
const APP_VER = "0.1.5.0322.2"
|
||||
|
||||
func init() {
|
||||
base.AppVer = APP_VER
|
||||
|
|
|
@ -41,19 +41,19 @@ var (
|
|||
Cfg *goconfig.ConfigFile
|
||||
MailService *Mailer
|
||||
|
||||
LogMode string
|
||||
LogConfig string
|
||||
|
||||
Cache cache.Cache
|
||||
CacheAdapter string
|
||||
CacheConfig string
|
||||
|
||||
PictureService string
|
||||
PictureRootPath string
|
||||
|
||||
LogMode string
|
||||
LogConfig string
|
||||
|
||||
SessionProvider string
|
||||
SessionConfig *session.Config
|
||||
SessionManager *session.Manager
|
||||
|
||||
PictureService string
|
||||
PictureRootPath string
|
||||
)
|
||||
|
||||
var Service struct {
|
||||
|
@ -182,6 +182,10 @@ func newSessionService() {
|
|||
SessionConfig.SessionIDHashFunc = Cfg.MustValue("session", "SESSION_ID_HASHFUNC", "sha1")
|
||||
SessionConfig.SessionIDHashKey = Cfg.MustValue("session", "SESSION_ID_HASHKEY")
|
||||
|
||||
if SessionProvider == "file" {
|
||||
os.MkdirAll(path.Dir(SessionConfig.ProviderConfig), os.ModePerm)
|
||||
}
|
||||
|
||||
var err error
|
||||
SessionManager, err = session.NewManager(SessionProvider, *SessionConfig)
|
||||
if err != nil {
|
||||
|
|
|
@ -111,6 +111,85 @@ const (
|
|||
Year = 12 * Month
|
||||
)
|
||||
|
||||
func computeTimeDiff(diff int64) (int64, string) {
|
||||
diffStr := ""
|
||||
switch {
|
||||
case diff <= 0:
|
||||
diff = 0
|
||||
diffStr = "now"
|
||||
case diff < 2:
|
||||
diff = 0
|
||||
diffStr = "1 second"
|
||||
case diff < 1*Minute:
|
||||
diffStr = fmt.Sprintf("%d seconds", diff)
|
||||
diff = 0
|
||||
|
||||
case diff < 2*Minute:
|
||||
diff -= 1 * Minute
|
||||
diffStr = "1 minute"
|
||||
case diff < 1*Hour:
|
||||
diffStr = fmt.Sprintf("%d minutes", diff/Minute)
|
||||
diff -= diff / Minute * Minute
|
||||
|
||||
case diff < 2*Hour:
|
||||
diff -= 1 * Hour
|
||||
diffStr = "1 hour"
|
||||
case diff < 1*Day:
|
||||
diffStr = fmt.Sprintf("%d hours", diff/Hour)
|
||||
diff -= diff / Hour * Hour
|
||||
|
||||
case diff < 2*Day:
|
||||
diff -= 1 * Day
|
||||
diffStr = "1 day"
|
||||
case diff < 1*Week:
|
||||
diffStr = fmt.Sprintf("%d days", diff/Day)
|
||||
diff -= diff / Day * Day
|
||||
|
||||
case diff < 2*Week:
|
||||
diff -= 1 * Week
|
||||
diffStr = "1 week"
|
||||
case diff < 1*Month:
|
||||
diffStr = fmt.Sprintf("%d weeks", diff/Week)
|
||||
diff -= diff / Week * Week
|
||||
|
||||
case diff < 2*Month:
|
||||
diff -= 1 * Month
|
||||
diffStr = "1 month"
|
||||
case diff < 1*Year:
|
||||
diffStr = fmt.Sprintf("%d months", diff/Month)
|
||||
diff -= diff / Month * Month
|
||||
|
||||
case diff < 2*Year:
|
||||
diff -= 1 * Year
|
||||
diffStr = "1 year"
|
||||
default:
|
||||
diffStr = fmt.Sprintf("%d years", diff/Year)
|
||||
diff = 0
|
||||
}
|
||||
return diff, diffStr
|
||||
}
|
||||
|
||||
// TimeSincePro calculates the time interval and generate full user-friendly string.
|
||||
func TimeSincePro(then time.Time) string {
|
||||
now := time.Now()
|
||||
diff := now.Unix() - then.Unix()
|
||||
|
||||
if then.After(now) {
|
||||
return "future"
|
||||
}
|
||||
|
||||
var timeStr, diffStr string
|
||||
for {
|
||||
if diff == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
diff, diffStr = computeTimeDiff(diff)
|
||||
timeStr += ", " + diffStr
|
||||
}
|
||||
return strings.TrimPrefix(timeStr, ", ")
|
||||
}
|
||||
|
||||
// TimeSince calculates the time interval and generate user-friendly string.
|
||||
func TimeSince(then time.Time) string {
|
||||
now := time.Now()
|
||||
|
@ -123,7 +202,6 @@ func TimeSince(then time.Time) string {
|
|||
}
|
||||
|
||||
switch {
|
||||
|
||||
case diff <= 0:
|
||||
return "now"
|
||||
case diff <= 2:
|
||||
|
@ -156,8 +234,10 @@ func TimeSince(then time.Time) string {
|
|||
case diff < 1*Year:
|
||||
return fmt.Sprintf("%d months %s", diff/Month, lbl)
|
||||
|
||||
case diff < 18*Month:
|
||||
case diff < 2*Year:
|
||||
return fmt.Sprintf("1 year %s", lbl)
|
||||
default:
|
||||
return fmt.Sprintf("%d years %s", diff/Year, lbl)
|
||||
}
|
||||
return then.String()
|
||||
}
|
||||
|
|
|
@ -17,7 +17,10 @@ import (
|
|||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
var startTime = time.Now()
|
||||
|
||||
var sysStatus struct {
|
||||
Uptime string
|
||||
NumGoroutine int
|
||||
|
||||
// General statistics.
|
||||
|
@ -58,6 +61,8 @@ var sysStatus struct {
|
|||
}
|
||||
|
||||
func updateSystemStatus() {
|
||||
sysStatus.Uptime = base.TimeSincePro(startTime)
|
||||
|
||||
m := new(runtime.MemStats)
|
||||
runtime.ReadMemStats(m)
|
||||
sysStatus.NumGoroutine = runtime.NumGoroutine()
|
||||
|
@ -88,8 +93,8 @@ func updateSystemStatus() {
|
|||
|
||||
sysStatus.NextGC = base.FileSize(int64(m.NextGC))
|
||||
sysStatus.LastGC = fmt.Sprintf("%.1fs", float64(time.Now().UnixNano()-int64(m.LastGC))/1000/1000/1000)
|
||||
sysStatus.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs/1000/1000/1000))
|
||||
sysStatus.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256]/1000/1000/1000))
|
||||
sysStatus.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs)/1000/1000/1000)
|
||||
sysStatus.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256])/1000/1000/1000)
|
||||
sysStatus.NumGC = m.NumGC
|
||||
}
|
||||
|
||||
|
@ -151,6 +156,9 @@ func Config(ctx *middleware.Context) {
|
|||
ctx.Data["CacheAdapter"] = base.CacheAdapter
|
||||
ctx.Data["CacheConfig"] = base.CacheConfig
|
||||
|
||||
ctx.Data["SessionProvider"] = base.SessionProvider
|
||||
ctx.Data["SessionConfig"] = base.SessionConfig
|
||||
|
||||
ctx.Data["PictureService"] = base.PictureService
|
||||
ctx.Data["PictureRootPath"] = base.PictureRootPath
|
||||
|
||||
|
|
|
@ -77,6 +77,25 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
Session Configuration
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<div><b>Session Provider:</b> {{.SessionProvider}}</div>
|
||||
<div><b>Cookie Name:</b> {{.SessionConfig.CookieName}}</div>
|
||||
<div><b>Enable Set Cookie:</b> <i class="fa fa{{if .SessionConfig.EnableSetCookie}}-check{{end}}-square-o"></i></div>
|
||||
<div><b>GC Interval Time:</b> {{.SessionConfig.GcIntervalTime}} seconds</div>
|
||||
<div><b>Session Life Time:</b> {{.SessionConfig.SessionLifeTime}} seconds</div>
|
||||
<div><b>HTTPS Only:</b> <i class="fa fa{{if .SessionConfig.CookieSecure}}-check{{end}}-square-o"></i></div>
|
||||
<div><b>Cookie Life Time:</b> {{.SessionConfig.CookieLifeTime}} seconds</div>
|
||||
<div><b>Session ID Hash Function:</b> {{.SessionConfig.SessionIDHashFunc}}</div>
|
||||
<div><b>Session ID Hash Key:</b> {{.SessionConfig.SessionIDHashKey}}</div>
|
||||
<div><b>Provider Config:</b> {{.SessionConfig.ProviderConfig}}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
Picture Configuration
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<div>Server Uptime: <b>{{.SysStatus.Uptime}}</b></div>
|
||||
<div>Current Goroutines: <b>{{.SysStatus.NumGoroutine}}</b></div>
|
||||
<hr/>
|
||||
<div>Current Memory Usage: <b>{{.SysStatus.MemAllocated}}</b></div>
|
||||
|
|
Loading…
Reference in New Issue