-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (39 loc) · 986 Bytes
/
main.go
File metadata and controls
46 lines (39 loc) · 986 Bytes
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
package main
import (
"os"
"github.com/ProxySafe/site-backend/src/app"
"github.com/ProxySafe/site-backend/src/app/config"
"github.com/cosiner/flag"
"gopkg.in/yaml.v2"
)
type Params struct {
ConfigFile string `names:"--config_dir, -c" usage:"configuration directory" default:"./config/config.yaml"`
LogsDir string `names:"--logs_dir, -l" usage:"log directory" default:"./var/log/"`
WebServerPort int `names:"--web_server_port, -wp" usage:"port if you need to run web server"`
}
func getParams() *Params {
params := &Params{}
err := flag.Commandline.ParseStruct(params)
if err != nil {
panic(err)
}
return params
}
func getConfig(params *Params) *config.Config {
content, err := os.ReadFile(params.ConfigFile)
if err != nil {
panic(err)
}
c := &config.Config{}
if err := yaml.Unmarshal(content, c); err != nil {
panic(err)
}
return c
}
func main() {
p := getParams()
c := getConfig(p)
a := app.NewApp(c)
a.Init()
a.Run(p.WebServerPort)
}