-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnetgate.go
More file actions
87 lines (67 loc) · 1.91 KB
/
netgate.go
File metadata and controls
87 lines (67 loc) · 1.91 KB
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
87
package main
import (
"flag"
"fmt"
"os"
"runtime"
"time"
_ "github.com/mrhaoxx/OpenNG/auth"
_ "github.com/mrhaoxx/OpenNG/init"
"github.com/mrhaoxx/OpenNG/log"
"github.com/mrhaoxx/OpenNG/ui"
"github.com/rs/zerolog"
zlog "github.com/rs/zerolog/log"
_ "github.com/mrhaoxx/OpenNG/plugins/expr"
)
var gitver = "dev"
var buildstamp = "dev-built"
var configfile = flag.String("config", "config.yaml", "the config file to load")
var printversion = flag.Bool("version", false, "print version and exit")
var helpmessage = flag.Bool("help", false, "print help message")
var printjsonschema = flag.Bool("jsonschema", false, "print json schema to stdout")
func main() {
zerolog.TimeFieldFormat = time.RFC3339Nano
zerolog.DurationFieldUnit = time.Second
zlog.Logger = zlog.Output(log.Loggers)
// zlog.Logger = zlog.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339Nano})
fmt.Fprintf(os.Stderr, "NetGATE - A Inbound Gateway\n")
flag.Parse()
if *helpmessage {
flag.PrintDefaults()
return
}
fmt.Fprintf(os.Stderr, `
_ _ _ ____ _ _____ _____
| \ | | ___| |_ / ___| / \|_ _| ____|
| \| |/ _ \ __| | _ / _ \ | | | _|
| |\ | __/ |_| |_| |/ ___ \| | | |___
|_| \_|\___|\__|\____/_/ \_\_| |_____|
%s %s
%s %s %s %s
config: %s
`,
gitver, buildstamp, runtime.Version(), runtime.GOOS, runtime.GOARCH, runtime.Compiler, *configfile)
switch {
case *printjsonschema:
os.Stdout.Write(ui.GenerateJsonSchema())
return
case *printversion:
return
}
r, err := os.ReadFile(*configfile)
if err != nil {
fmt.Println(err.Error())
return
}
ui.ConfigFile = *configfile
_start := time.Now()
if err := ui.LoadCfg(r, false); err != nil {
zlog.Error().
Str("type", "sys/config").
Str("error", err.Error()).
Msg("configuration load failed")
os.Exit(-1)
}
fmt.Fprintf(os.Stderr, "configuration from %s loaded in %s\n", *configfile, time.Since(_start).String())
select {}
}