-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.go
70 lines (54 loc) · 1.86 KB
/
config.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
package main
import (
"encoding/json"
"flag"
"os"
rcon "github.com/forewing/csgo-rcon"
"github.com/forewing/webrcon-server/version"
)
// Flags holds configs
type Flags struct {
Address *string `json:",omitempty"`
Password *string `json:",omitempty"`
Timeout *float64 `json:",omitempty"`
Preset *string `json:",omitempty"`
Config *string `json:",omitempty"`
PublicAddress *string `json:",omitempty"`
Bind *string `json:",omitempty"`
BasicAuthUsername *string `json:",omitempty"`
BasicAuthPassword *string `json:",omitempty"`
Debug *bool `json:",omitempty"`
}
var (
flags Flags = Flags{
Address: flag.String("addr", rcon.DefaultAddress, "`address` of the server RCON, in the format of HOST:PORT"),
Password: flag.String("pass", rcon.DefaultPassword, "`password` of the RCON"),
Timeout: flag.Float64("timeout", rcon.DefaultTimeout.Seconds(), "`timeout`(seconds) of the connection"),
Preset: flag.String("preset", "", "use `preset`(path), empty for default csgo config"),
Config: flag.String("conf", "", "load configs from `file` instead of flags"),
PublicAddress: flag.String("public-addr", "", "redirect target(public `address`) for /api/connect, empty for disabled"),
Bind: flag.String("bind", "0.0.0.0:8080", "webrcon-server bind `address`"),
BasicAuthUsername: flag.String("admin-name", "", "basicauth `username` for path /api/exec"),
BasicAuthPassword: flag.String("admin-pass", "", "basicauth `password` for path /api/exec"),
Debug: flag.Bool("debug", false, "turn on debug mode"),
}
flagVersion = flag.Bool("version", false, "display versions")
)
func init() {
flag.Parse()
if *flagVersion {
version.Display()
os.Exit(0)
}
if len(*flags.Config) == 0 {
return
}
data, err := os.ReadFile(*flags.Config)
if err != nil {
panic(err)
}
err = json.Unmarshal(data, &flags)
if err != nil {
panic(err)
}
}