-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
56 lines (46 loc) · 1.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"flag"
"log"
"os"
"strings"
"github.com/spf13/viper"
"github.com/broodjeaap/go-watch/web"
)
func main() {
writeConfFlag := flag.String("writeConfig", "-", "Path to write template config to")
var printConfigFlag bool
flag.BoolVar(&printConfigFlag, "printConfig", false, "Print the template config to stdout")
flag.Parse()
if *writeConfFlag != "-" {
conf, err := web.EMBED_FS.ReadFile("config.tmpl")
if err != nil {
log.Fatalln("Could not read config.tmpl")
}
os.WriteFile(*writeConfFlag, conf, 0666)
log.Println("Wrote template config to:", *writeConfFlag)
return
}
if printConfigFlag {
conf, err := web.EMBED_FS.ReadFile("config.tmpl")
if err != nil {
log.Fatalln("Could not read config.tmpl")
}
log.SetFlags(0)
log.Println(string(conf))
return
}
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("/config")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetEnvPrefix("GOWATCH")
viper.AutomaticEnv()
err := viper.ReadInConfig()
if err != nil {
log.Println("Could not load config file, using env/defaults")
}
web := web.NewWeb()
web.Run()
}