func main() { logger := lager.NewLogger("lattice-app") if quiet { logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO)) } else { logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG)) } port := os.Getenv("PORT") if port == "" { port = "8080" } logger.Info("lattice-app.starting", lager.Data{"port": port}) handler, err := rata.NewRouter(routes.Routes, handlers.New(logger)) if err != nil { logger.Fatal("router.creation.failed", err) } index, err := helpers.FetchIndex() appName := helpers.FetchAppName() go func() { t := time.NewTicker(time.Second) for { <-t.C if err != nil { fmt.Fprintf(os.Stderr, "Failed to fetch index: %s\n", err.Error()) } else { fmt.Println(fmt.Sprintf("%s. Says %s. on index: %d", appName, message, index)) } } }() server := ifrit.Envoke(http_server.New(":"+port, handler)) logger.Info("lattice-app.up", lager.Data{"port": port}) err = <-server.Wait() if err != nil { logger.Error("farewell", err) } logger.Info("farewell") }
func (p *Hello) ServeHTTP(w http.ResponseWriter, r *http.Request) { index, _ := helpers.FetchIndex() appName := helpers.FetchAppName() if appName == "Lattice-app" { appName = "" } else { appName = " - " + appName } colors := helpers.FetchColors() styledColoredTemplate.Execute(w, ColoredBody{Body: fmt.Sprintf(` <div class="hello"> Lattice%s </div> <div class="my-index">My Index Is</div> <div class="index">%d</div> <div class="mid-color">Uptime: %s</div> <div class="bottom-color"></div> `, appName, index, time.Since(p.Time)), Colors: colors}) }