Esempio n. 1
0
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()
}
Esempio n. 2
0
func NewRouter(c *container.ContainerBag) *martini.ClassicMartini {
	var (
		indexHandler    = handler.NewIndexHandler(c)
		buildersHandler = handler.NewBuildersHandler(c)
	)

	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{
			{
				"genericSize": func() string {
					return c.GenericSize
				},
				"buildbotUrl": func() string {
					return c.BuildBotUrl
				},
				"hashedUrl": func() string {
					return c.HashedUrl
				},
				"displayEmptyBuilder": func() bool {
					return c.EmptyBuilders
				},
			},
		},
	}))

	router.Get("/", indexHandler.ServeHTTP)
	router.Get("/builders", buildersHandler.ServeHTTP)

	handler.AddWs(router, c)

	return router
}