-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (56 loc) · 1.53 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
package main
import (
"embed"
"flag"
"fmt"
"os"
"github.com/kevincobain2000/instachart/pkg"
)
//go:embed all:frontend/dist/*
var publicDir embed.FS
type Flags struct {
host string
port string
baseUrl string
allowedRemoteDomains string
pprofHost string
pprofPort string
}
var f Flags
var version = "dev"
func main() {
if len(os.Args) > 1 && os.Args[1] == "version" {
fmt.Println(version)
return
}
SetupFlags()
e := pkg.NewEcho(f.baseUrl, publicDir)
pkg.GracefulServerWithPid(e, f.host, f.port)
}
func SetupFlags() {
flag.StringVar(&f.host, "host", "localhost", "host to serve")
flag.StringVar(&f.port, "port", "3001", "port to serve")
flag.StringVar(&f.baseUrl, "base-url", "/", "base url with slash")
flag.StringVar(&f.allowedRemoteDomains, "remote-domains", "", "csv list of allowed domains for remote fetching")
flag.StringVar(&f.pprofHost, "pprof-host", "", "pprof host")
flag.StringVar(&f.pprofPort, "pprof-port", "", "pprof port")
flag.Parse()
if f.pprofHost != "" && os.Getenv("PPROF_HOST") == "" {
err := os.Setenv("PPROF_HOST", f.pprofHost)
if err != nil {
pkg.Logger().Error(err)
}
}
if f.pprofPort != "" && os.Getenv("PPROF_PORT") == "" {
err := os.Setenv("PPROF_PORT", f.pprofPort)
if err != nil {
pkg.Logger().Error(err)
}
}
if f.allowedRemoteDomains != "" && os.Getenv("ALLOWED_REMOTE_DOMAINS") == "" {
err := os.Setenv("ALLOWED_REMOTE_DOMAINS", f.allowedRemoteDomains)
if err != nil {
pkg.Logger().Error(err)
}
}
}