legit/main.go

42 lines
804 B
Go

package main
import (
"flag"
"fmt"
"html/template"
"log"
"net/http"
"path/filepath"
"git.icyphox.sh/legit/config"
"git.icyphox.sh/legit/routes"
)
func main() {
const version string = "0.2.x"
var cfg string
flag.StringVar(&cfg, "config", "./config.yaml", "path to config file")
flag.Parse()
c, err := config.Read(cfg, version)
if err != nil {
log.Fatal(err)
}
if err := UnveilPaths([]string{
c.Dirs.Static,
c.Repo.ScanPath,
c.Dirs.Templates,
},
"r"); err != nil {
log.Fatalf("unveil: %s", err)
}
tpath := filepath.Join(c.Dirs.Templates, "*")
t := template.Must(template.ParseGlob(tpath))
mux := routes.Handlers(c, t)
addr := fmt.Sprintf("%s:%d", c.Server.Host, c.Server.Port)
log.Println("starting server on", addr)
log.Fatal(http.ListenAndServe(addr, mux))
}