all repos — legit @ 5ba4a5747fdd66ac0ddf5742cf4c275b808df36d

Unnamed repository; edit this file 'description' to name the repository.

main.go (view raw)

 1package main
 2
 3import (
 4	"fmt"
 5	"log"
 6	"net/http"
 7
 8	"git.icyphox.sh/legit/config"
 9	"git.icyphox.sh/legit/routes"
10	"github.com/alexflint/go-arg"
11)
12
13var (
14	version   = "dev"
15	buildDate = "unknown"
16)
17
18type args struct {
19	Config string `arg:"--config" default:"./config.yaml" help:"path to config file"`
20}
21
22func (args) Description() string {
23	return fmt.Sprintf("legit %s (built %s)", version, buildDate)
24}
25
26func (args) Version() string {
27	return fmt.Sprintf("legit %s (built %s)", version, buildDate)
28}
29
30func main() {
31	var a args
32	arg.MustParse(&a)
33
34	c, err := config.Read(a.Config)
35	if err != nil {
36		log.Fatal(err)
37	}
38
39	if err := UnveilPaths([]string{
40		c.Dirs.Static,
41		c.Repo.ScanPath,
42		c.Dirs.Templates,
43	},
44		"r"); err != nil {
45		log.Fatalf("unveil: %s", err)
46	}
47
48	mux := routes.Handlers(c)
49	addr := fmt.Sprintf("%s:%d", c.Server.Host, c.Server.Port)
50	log.Println("starting server on", addr)
51	log.Fatal(http.ListenAndServe(addr, mux))
52}