-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
59 lines (56 loc) · 1.27 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
package main
import (
"flag"
"github.com/juzeon/epok-forwarder/api"
"github.com/juzeon/epok-forwarder/cli"
"github.com/juzeon/epok-forwarder/data"
"github.com/juzeon/epok-forwarder/forwarder"
"github.com/juzeon/epok-forwarder/geo"
"github.com/juzeon/epok-forwarder/util"
"log/slog"
"os"
)
type Flags struct {
configFile string
reload bool
help bool
generate bool
}
func main() { // TODO block based on geo
var flg Flags
flag.StringVar(&flg.configFile, "c", "config.yml", "specify a config file")
flag.BoolVar(&flg.reload, "r", false, "perform hot reload")
flag.BoolVar(&flg.help, "h", false, "get help")
flag.BoolVar(&flg.generate, "g", false, "generate cli env based on the config file")
flag.Parse()
cli.InitConfig()
if flg.reload {
cli.Reload()
}
if flg.help {
flag.PrintDefaults()
os.Exit(0)
}
config, err := data.ReadConfig(flg.configFile)
if err != nil {
util.ErrExit(err)
}
if flg.generate {
cli.Generate(config.BaseConfig)
}
geo.Setup()
slog.Info("Starting forwarder...")
fwd, err := forwarder.New(config)
if err != nil {
util.ErrExit(err)
}
err = fwd.StartAsync()
if err != nil {
util.ErrExit(err)
}
slog.Info("All listeners are on.")
err = api.StartServer(flg.configFile, config, fwd)
if err != nil {
util.ErrExit(err)
}
}