forked from ghophp/buildbot-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (61 loc) · 1.93 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"html/template"
"strconv"
bb "github.com/ghophp/buildbot-dashboard/buildbot"
cc "github.com/ghophp/buildbot-dashboard/cache"
"github.com/ghophp/buildbot-dashboard/config"
"github.com/ghophp/buildbot-dashboard/handler"
"github.com/ghophp/buildbot-dashboard/pool"
"github.com/ghophp/render"
"github.com/go-martini/martini"
"github.com/martini-contrib/staticbin"
"github.com/op/go-logging"
)
const LoggerPrefix = "BUILDBOT-DASHBOARD"
var log = logging.MustGetLogger(LoggerPrefix)
// Log format string. Everything except the message has a custom color
// which is dependent on the log level. Many fields have a custom output
// formatting too, eg. the time returns the hour down to the milli second.
var format = logging.MustStringFormatter(
`%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
)
func main() {
logging.SetFormatter(format)
cfg, err := config.NewConfig(&config.FlagLoader{})
if err != nil {
panic(err)
}
var (
cache = cc.NewFileCache()
buildbot = bb.NewBuildbotApi(cfg.BuildBotUrl, pool.NewRequestPool(), log)
indexHandler = handler.NewIndexHandler()
buildersHandler = handler.NewBuildersHandler(cfg, buildbot, cache, log)
)
router := martini.Classic()
router.Use(staticbin.Static("static/assets", Asset))
router.Use(render.RendererBin(Asset, AssetNames(), render.Options{
Directory: "static/templates",
Layout: "layout",
Extensions: []string{".tmpl", ".html"},
Charset: "UTF-8",
IndentJSON: true,
Funcs: []template.FuncMap{
{
"refreshSec": func() string {
return strconv.Itoa(cfg.RefreshSec)
},
"buildbotUrl": func() string {
return buildbot.GetUrl()
},
"hashedUrl": func() string {
return cfg.HashedUrl
},
},
},
}))
router.Get("/", indexHandler.ServeHTTP)
router.Get("/builders", buildersHandler.GetBuilders)
router.Get("/builder/:id", buildersHandler.GetBuilder)
router.Run()
}