package main import ( "hacklab.nilfm.cc/quartzgun/renderer" "hacklab.nilfm.cc/quartzgun/router" "hacklab.nilfm.cc/quartzgun/util" "net/http" "path/filepath" "html/template" ) func withTitleAndStreamsAndSentry(next http.Handler, cfg Config, sentry *Sentry) http.Handler { handlerFunc := func(w http.ResponseWriter, req *http.Request) { util.AddContextValue(req, "title", cfg.Name) util.AddContextValue(req, "streams", cfg.Streams) util.AddContextValue(req, "sentry", sentry) next.ServeHTTP(w, req) } return http.HandlerFunc(handlerFunc) } type Sentry struct {} func (self *Sentry) GetStatus(url string) int { resp, err := http.Get(url) if err != nil { return 500 } else { return resp.StatusCode } } func main() { cfg := ReadConfig() templateRoot := filepath.Join(cfg.DataDir, "templates") rtr := &router.Router{ StaticPaths: map[string]string{ "/static/": filepath.Join(cfg.DataDir, "static"), }, Fallback: *template.Must(template.ParseFiles( filepath.Join(templateRoot, "err.html"), )), } rtr.Get("/", withTitleAndStreamsAndSentry( renderer.Template( filepath.Join(templateRoot, "radio.html"), ), *cfg, &Sentry{}, )) http.ListenAndServe(cfg.ListenAddress, rtr) }