-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
86 lines (70 loc) · 2.68 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Package main
package main
import (
"context"
"flag"
"fmt"
"io"
"os"
"os/signal"
"syscall"
"github.com/joho/godotenv"
"github.com/rs/zerolog/log"
"github.com/valkyrie-fnd/valkyrie/configs"
"github.com/valkyrie-fnd/valkyrie/server"
_ "github.com/joho/godotenv/autoload" // load .env file automatically
)
var appVersion = "devel"
// banner ascii art generated using https://textkool.com/en/ascii-art-generator?hl=default&vl=default&font=Bloody&text=Valkyrie
const banner = `
██▒ █▓ ▄▄▄ ██▓ ██ ▄█▀▓██ ██▓ ██▀███ ██▓▓█████
▓██░ █▒▒████▄ ▓██▒ ██▄█▒ ▒██ ██▒▓██ ▒ ██▒▓██▒▓█ ▀
▓██ █▒░▒██ ▀█▄ ▒██░ ▓███▄░ ▒██ ██░▓██ ░▄█ ▒▒██▒▒███
▒██ █░░░██▄▄▄▄██ ▒██░ ▓██ █▄ ░ ▐██▓░▒██▀▀█▄ ░██░▒▓█ ▄
▒▀█░ ▓█ ▓██▒░██████▒▒██▒ █▄ ░ ██▒▓░░██▓ ▒██▒░██░░▒████▒
░ ▐░ ▒▒ ▓▒█░░ ▒░▓ ░▒ ▒▒ ▓▒ ██▒▒▒ ░ ▒▓ ░▒▓░░▓ ░░ ▒░ ░
░ ░░ ▒ ▒▒ ░░ ░ ▒ ░░ ░▒ ▒░ ▓██ ░▒░ ░▒ ░ ▒░ ▒ ░ ░ ░ ░
░░ ░ ▒ ░ ░ ░ ░░ ░ ▒ ▒ ░░ ░░ ░ ▒ ░ ░
░ ░ ░ ░ ░░ ░ ░ ░ ░ ░ ░ ░
░ ░ ░
`
func main() {
os.Exit(mainReal(listenForSignal(), os.Stdout))
}
func mainReal(ctx context.Context, out io.Writer) int {
// Load .env.local if found
_ = godotenv.Load(".env.local")
versionFlag := flag.Bool("version", false, "Print the version")
// Read config location
configFilePath := flag.String("config",
"",
"Path to Valkyrie configuration yaml file")
flag.Parse()
if *versionFlag {
_, _ = fmt.Fprintf(out, "Version: %s\n", appVersion)
return 0
}
cfg, err := configs.Read(configFilePath)
if err != nil {
log.Err(err).Msg("Failed to read config")
return 1
}
cfg.Version = appVersion
// Print banner
_, _ = fmt.Fprintf(out, "%s\n", banner)
v, err := server.NewValkyrie(ctx, cfg)
if err != nil {
return 1
}
v.Run(func() {})
return 0
}
func listenForSignal() context.Context {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
go func() {
<-ctx.Done()
log.Info().Msg("Shutting down")
cancel()
}()
return ctx
}