federated-dash/cmd/web/main.go

49 lines
868 B
Go
Raw Normal View History

2024-06-25 17:35:30 +00:00
package main
import (
"html/template"
"log/slog"
"net/http"
"os"
)
type application struct {
logger *slog.Logger
templateCache map[string]*template.Template
2024-06-25 20:17:08 +00:00
tier string
2024-06-27 17:53:42 +00:00
host string
2024-06-25 17:35:30 +00:00
}
func main() {
//Set up logger
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
AddSource: true,
}))
2024-06-27 17:53:42 +00:00
//Get env variables
tier := os.Getenv("TIER")
if len(tier) == 0 {
tier = "starter"
}
host := os.Getenv("HOST")
if len(host) == 0 {
logger.Error("Must specify host name.")
os.Exit(1)
}
2024-06-25 17:35:30 +00:00
//Set up template cache
templateCache, err := newTemplateCache()
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
//Set up application data
app := application {
logger: logger,
templateCache: templateCache,
2024-06-27 17:53:42 +00:00
tier: tier,
host: host,
2024-06-25 17:35:30 +00:00
}
2024-06-27 17:53:42 +00:00
err = http.ListenAndServe(":8080", app.routes())
2024-06-25 17:35:30 +00:00
logger.Error(err.Error())
os.Exit(1)
}