legit/main.go

43 lines
813 B
Go
Raw Permalink Normal View History

2022-12-11 05:52:47 +00:00
package main
import (
"flag"
2022-12-12 17:28:23 +00:00
"fmt"
"html/template"
2022-12-11 05:52:47 +00:00
"log"
"net/http"
"path/filepath"
2022-12-11 05:52:47 +00:00
2022-12-19 03:32:23 +00:00
"git.icyphox.sh/legit/config"
"git.icyphox.sh/legit/routes"
2022-12-11 05:52:47 +00:00
)
func main() {
2023-02-22 04:34:16 +00:00
const version string = "0.2.9999-nilix"
2022-12-11 05:52:47 +00:00
var cfg string
flag.StringVar(&cfg, "config", "./config.yaml", "path to config file")
flag.Parse()
2023-02-04 16:34:21 +00:00
c, err := config.Read(cfg, version)
2022-12-11 05:52:47 +00:00
if err != nil {
log.Fatal(err)
}
2022-12-22 05:50:02 +00:00
if err := UnveilPaths([]string{
c.Dirs.Static,
c.Repo.ScanPath,
2022-12-22 05:52:47 +00:00
c.Dirs.Templates,
},
2022-12-22 05:50:02 +00:00
"r"); err != nil {
log.Fatalf("unveil: %s", err)
2022-12-21 14:17:33 +00:00
}
tpath := filepath.Join(c.Dirs.Templates, "*")
t := template.Must(template.ParseGlob(tpath))
2022-12-18 05:34:11 +00:00
mux := routes.Handlers(c, t)
2022-12-12 17:28:23 +00:00
addr := fmt.Sprintf("%s:%d", c.Server.Host, c.Server.Port)
log.Println("starting server on", addr)
log.Fatal(http.ListenAndServe(addr, mux))
2022-12-11 05:52:47 +00:00
}