1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:04:39 -07:00

misc/dashboard/codereview: don't depend on map iteration order for unit calculation.

Fix auth requirements for /gc endpoint too.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6133049
This commit is contained in:
David Symonds 2012-04-28 09:47:15 +10:00
parent a0f7c6c658
commit 24cce5c60c
2 changed files with 12 additions and 9 deletions

View File

@ -16,7 +16,7 @@ handlers:
- url: /_ah/queue/go/delay
script: _go_app
login: admin
- url: /update-cl
- url: /(gc|update-cl)
script: _go_app
login: admin
- url: /.*

View File

@ -80,16 +80,19 @@ func (cl *CL) LGTMHTML() template.HTML {
func (cl *CL) ModifiedAgo() string {
// Just the first non-zero unit.
units := map[string]time.Duration{
"d": 24 * time.Hour,
"h": time.Hour,
"m": time.Minute,
"s": time.Second,
units := [...]struct {
suffix string
unit time.Duration
}{
{"d", 24 * time.Hour},
{"h", time.Hour},
{"m", time.Minute},
{"s", time.Second},
}
d := time.Now().Sub(cl.Modified)
for suffix, u := range units {
if d > u {
return fmt.Sprintf("%d%s", d/u, suffix)
for _, u := range units {
if d > u.unit {
return fmt.Sprintf("%d%s", d/u.unit, u.suffix)
}
}
return "just now"