Skip to content

Commit 5edd57e

Browse files
committed
Merge branch 'master' of github.com:gogits/gogs
2 parents 076fc98 + cd070b5 commit 5edd57e

File tree

9 files changed

+134
-26
lines changed

9 files changed

+134
-26
lines changed

.gopmfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ path=github.com/gogits/gogs
44
[deps]
55
github.com/codegangsta/cli=
66
github.com/codegangsta/martini=
7-
github.com/martini-contrib/sessions=
87
github.com/Unknwon/com=
98
github.com/Unknwon/cae=
109
github.com/Unknwon/goconfig=

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ There are two ways to install Gogs:
4343
## Acknowledgments
4444

4545
- Logo is inspired by [martini](https://github.com/martini-contrib).
46-
- Mail service is based on [WeTalk](https://github.com/beego/wetalk).
46+
- Mail Service is based on [WeTalk](https://github.com/beego/wetalk).
4747
- System Monitor Status is based on [GoBlog](https://github.com/fuxiaohei/goblog).
4848

4949
## Contributors

conf/app.ini

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,25 @@ HOST =
7575
[session]
7676
; Either "memory", "file", "redis" or "mysql", default is "memory"
7777
PROVIDER = file
78-
; provider config
78+
; Provider config options
7979
; memory: not have any config yet
80-
; file: session file path
81-
; e.g. tmp/sessions
82-
; redis: config like redis server addr,poolSize,password
83-
; e.g. 127.0.0.1:6379,100,astaxie
84-
; mysql: go-sql-driver/mysql dsn config string
85-
; e.g. root:password@/session_table
80+
; file: session file path, e.g. data/sessions
81+
; redis: config like redis server addr, poolSize, password, e.g. 127.0.0.1:6379,100,astaxie
82+
; mysql: go-sql-driver/mysql dsn config string, e.g. root:password@/session_table
8683
PROVIDER_CONFIG = data/sessions
87-
; session cookie name
84+
; Session cookie name
8885
COOKIE_NAME = i_like_gogits
89-
; if you use session in https only, default is false
86+
; If you use session in https only, default is false
9087
COOKIE_SECURE = false
91-
; enable set cookie, default is true
88+
; Enable set cookie, default is true
9289
ENABLE_SET_COOKIE = true
93-
; session gc time interval, default is 86400
90+
; Session GC time interval, default is 86400
9491
GC_INTERVAL_TIME = 86400
95-
; session life time, default is 86400
92+
; Session life time, default is 86400
9693
SESSION_LIFE_TIME = 86400
9794
; session id hash func, Either "sha1", "sha256" or "md5" default is sha1
9895
SESSION_ID_HASHFUNC = sha1
99-
; session hash key, default is use random string
96+
; Session hash key, default is use random string
10097
SESSION_ID_HASHKEY =
10198

10299
[picture]

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
2121
const go12tag = true
2222

23-
const APP_VER = "0.1.5.0322"
23+
const APP_VER = "0.1.5.0322.2"
2424

2525
func init() {
2626
base.AppVer = APP_VER

modules/base/conf.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ var (
4141
Cfg *goconfig.ConfigFile
4242
MailService *Mailer
4343

44+
LogMode string
45+
LogConfig string
46+
4447
Cache cache.Cache
4548
CacheAdapter string
4649
CacheConfig string
4750

48-
PictureService string
49-
PictureRootPath string
50-
51-
LogMode string
52-
LogConfig string
53-
5451
SessionProvider string
5552
SessionConfig *session.Config
5653
SessionManager *session.Manager
54+
55+
PictureService string
56+
PictureRootPath string
5757
)
5858

5959
var Service struct {
@@ -182,6 +182,10 @@ func newSessionService() {
182182
SessionConfig.SessionIDHashFunc = Cfg.MustValue("session", "SESSION_ID_HASHFUNC", "sha1")
183183
SessionConfig.SessionIDHashKey = Cfg.MustValue("session", "SESSION_ID_HASHKEY")
184184

185+
if SessionProvider == "file" {
186+
os.MkdirAll(path.Dir(SessionConfig.ProviderConfig), os.ModePerm)
187+
}
188+
185189
var err error
186190
SessionManager, err = session.NewManager(SessionProvider, *SessionConfig)
187191
if err != nil {

modules/base/tool.go

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,85 @@ const (
115115
Year = 12 * Month
116116
)
117117

118+
func computeTimeDiff(diff int64) (int64, string) {
119+
diffStr := ""
120+
switch {
121+
case diff <= 0:
122+
diff = 0
123+
diffStr = "now"
124+
case diff < 2:
125+
diff = 0
126+
diffStr = "1 second"
127+
case diff < 1*Minute:
128+
diffStr = fmt.Sprintf("%d seconds", diff)
129+
diff = 0
130+
131+
case diff < 2*Minute:
132+
diff -= 1 * Minute
133+
diffStr = "1 minute"
134+
case diff < 1*Hour:
135+
diffStr = fmt.Sprintf("%d minutes", diff/Minute)
136+
diff -= diff / Minute * Minute
137+
138+
case diff < 2*Hour:
139+
diff -= 1 * Hour
140+
diffStr = "1 hour"
141+
case diff < 1*Day:
142+
diffStr = fmt.Sprintf("%d hours", diff/Hour)
143+
diff -= diff / Hour * Hour
144+
145+
case diff < 2*Day:
146+
diff -= 1 * Day
147+
diffStr = "1 day"
148+
case diff < 1*Week:
149+
diffStr = fmt.Sprintf("%d days", diff/Day)
150+
diff -= diff / Day * Day
151+
152+
case diff < 2*Week:
153+
diff -= 1 * Week
154+
diffStr = "1 week"
155+
case diff < 1*Month:
156+
diffStr = fmt.Sprintf("%d weeks", diff/Week)
157+
diff -= diff / Week * Week
158+
159+
case diff < 2*Month:
160+
diff -= 1 * Month
161+
diffStr = "1 month"
162+
case diff < 1*Year:
163+
diffStr = fmt.Sprintf("%d months", diff/Month)
164+
diff -= diff / Month * Month
165+
166+
case diff < 2*Year:
167+
diff -= 1 * Year
168+
diffStr = "1 year"
169+
default:
170+
diffStr = fmt.Sprintf("%d years", diff/Year)
171+
diff = 0
172+
}
173+
return diff, diffStr
174+
}
175+
176+
// TimeSincePro calculates the time interval and generate full user-friendly string.
177+
func TimeSincePro(then time.Time) string {
178+
now := time.Now()
179+
diff := now.Unix() - then.Unix()
180+
181+
if then.After(now) {
182+
return "future"
183+
}
184+
185+
var timeStr, diffStr string
186+
for {
187+
if diff == 0 {
188+
break
189+
}
190+
191+
diff, diffStr = computeTimeDiff(diff)
192+
timeStr += ", " + diffStr
193+
}
194+
return strings.TrimPrefix(timeStr, ", ")
195+
}
196+
118197
// TimeSince calculates the time interval and generate user-friendly string.
119198
func TimeSince(then time.Time) string {
120199
now := time.Now()
@@ -127,7 +206,6 @@ func TimeSince(then time.Time) string {
127206
}
128207

129208
switch {
130-
131209
case diff <= 0:
132210
return "now"
133211
case diff <= 2:
@@ -160,8 +238,10 @@ func TimeSince(then time.Time) string {
160238
case diff < 1*Year:
161239
return fmt.Sprintf("%d months %s", diff/Month, lbl)
162240

163-
case diff < 18*Month:
241+
case diff < 2*Year:
164242
return fmt.Sprintf("1 year %s", lbl)
243+
default:
244+
return fmt.Sprintf("%d years %s", diff/Year, lbl)
165245
}
166246
return then.String()
167247
}

routers/admin/admin.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import (
1717
"github.com/gogits/gogs/modules/middleware"
1818
)
1919

20+
var startTime = time.Now()
21+
2022
var sysStatus struct {
23+
Uptime string
2124
NumGoroutine int
2225

2326
// General statistics.
@@ -58,6 +61,8 @@ var sysStatus struct {
5861
}
5962

6063
func updateSystemStatus() {
64+
sysStatus.Uptime = base.TimeSincePro(startTime)
65+
6166
m := new(runtime.MemStats)
6267
runtime.ReadMemStats(m)
6368
sysStatus.NumGoroutine = runtime.NumGoroutine()
@@ -88,8 +93,8 @@ func updateSystemStatus() {
8893

8994
sysStatus.NextGC = base.FileSize(int64(m.NextGC))
9095
sysStatus.LastGC = fmt.Sprintf("%.1fs", float64(time.Now().UnixNano()-int64(m.LastGC))/1000/1000/1000)
91-
sysStatus.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs/1000/1000/1000))
92-
sysStatus.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256]/1000/1000/1000))
96+
sysStatus.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs)/1000/1000/1000)
97+
sysStatus.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256])/1000/1000/1000)
9398
sysStatus.NumGC = m.NumGC
9499
}
95100

@@ -151,6 +156,9 @@ func Config(ctx *middleware.Context) {
151156
ctx.Data["CacheAdapter"] = base.CacheAdapter
152157
ctx.Data["CacheConfig"] = base.CacheConfig
153158

159+
ctx.Data["SessionProvider"] = base.SessionProvider
160+
ctx.Data["SessionConfig"] = base.SessionConfig
161+
154162
ctx.Data["PictureService"] = base.PictureService
155163
ctx.Data["PictureRootPath"] = base.PictureRootPath
156164

templates/admin/config.tmpl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@
7777
</div>
7878
</div>
7979

80+
<div class="panel panel-default">
81+
<div class="panel-heading">
82+
Session Configuration
83+
</div>
84+
85+
<div class="panel-body">
86+
<div><b>Session Provider:</b> {{.SessionProvider}}</div>
87+
<div><b>Cookie Name:</b> {{.SessionConfig.CookieName}}</div>
88+
<div><b>Enable Set Cookie:</b> <i class="fa fa{{if .SessionConfig.EnableSetCookie}}-check{{end}}-square-o"></i></div>
89+
<div><b>GC Interval Time:</b> {{.SessionConfig.GcIntervalTime}} seconds</div>
90+
<div><b>Session Life Time:</b> {{.SessionConfig.SessionLifeTime}} seconds</div>
91+
<div><b>HTTPS Only:</b> <i class="fa fa{{if .SessionConfig.CookieSecure}}-check{{end}}-square-o"></i></div>
92+
<div><b>Cookie Life Time:</b> {{.SessionConfig.CookieLifeTime}} seconds</div>
93+
<div><b>Session ID Hash Function:</b> {{.SessionConfig.SessionIDHashFunc}}</div>
94+
<div><b>Session ID Hash Key:</b> {{.SessionConfig.SessionIDHashKey}}</div>
95+
<div><b>Provider Config:</b> {{.SessionConfig.ProviderConfig}}</div>
96+
</div>
97+
</div>
98+
8099
<div class="panel panel-default">
81100
<div class="panel-heading">
82101
Picture Configuration

templates/admin/dashboard.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</div>
2020

2121
<div class="panel-body">
22+
<div>Server Uptime: <b>{{.SysStatus.Uptime}}</b></div>
2223
<div>Current Goroutines: <b>{{.SysStatus.NumGoroutine}}</b></div>
2324
<hr/>
2425
<div>Current Memory Usage: <b>{{.SysStatus.MemAllocated}}</b></div>

0 commit comments

Comments
 (0)