-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
81 lines (71 loc) · 2.81 KB
/
flags.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
71
72
73
74
75
76
77
78
79
80
81
// flags
package main
import (
"encoding/json"
"flag"
"os"
)
type Config struct {
DebugLevel int
DebugTemplates bool
HTTPPort int
HTTPHost string
MySqlUser string
MySqlPassword string
MySqlDatabase string
MySqlHost string
MySqlPort int
SSOClientID string
SSOClientSecret string
SSOCallbackURL string
SchedulerMemberTracking bool
}
var (
config *Config
)
func ParseConfigFlags() (*Config, error) {
debugLevelFlag := flag.Int("debug", 3, "Sets the debug level (0-9), lower number displays more messages")
debugTemplatesFlag := flag.Bool("debugtemplates", false, "Toggles a complete rebuild for all templates on each request")
httpPortFlag := flag.Int("port", 3000, "Port for the webserver to bind to")
httpHostFlag := flag.String("host", "0.0.0.0", "Hostname for the webserver to bind to")
mysqlUserFlag := flag.String("mysqluser", "", "Username for authenticating to the MySQL server")
mysqlPasswordFlag := flag.String("mysqlpassword", "", "Password for authenticating to the MySQL server")
mysqlDatabaseFlag := flag.String("mysqldatabase", "", "Database to use with the MySQL server")
mysqlHostFlag := flag.String("mysqlhost", "localhost", "Hostname of the MySQL server")
mysqlPortFlag := flag.Int("mysqlport", 3306, "Port of the MySQL server")
ssoClientIDFlag := flag.String("ssoid", "", "EVE Online Application Client ID")
ssoClientSecretFlag := flag.String("ssosecret", "", "EVE Online Application Client Secret")
ssoCallbackURLFlag := flag.String("ssocallback", "", "EVE Online Application Callback URL")
schedulerMemberTrackingFlag := flag.Bool("membertracking", false, "Enables automatic member list updates via the EVE API (requires corp API key)")
configFileFlag := flag.String("config", "", "Config file to parse commandline parameters from")
flag.Parse()
var conf *Config
if len(*configFileFlag) > 0 {
configFile, err := os.Open(*configFileFlag)
if err != nil {
return &Config{}, err
}
decoder := json.NewDecoder(configFile)
err = decoder.Decode(&conf)
if err != nil {
return &Config{}, err
}
} else {
conf = &Config{
DebugLevel: *debugLevelFlag,
DebugTemplates: *debugTemplatesFlag,
HTTPPort: *httpPortFlag,
HTTPHost: *httpHostFlag,
MySqlUser: *mysqlUserFlag,
MySqlPassword: *mysqlPasswordFlag,
MySqlDatabase: *mysqlDatabaseFlag,
MySqlHost: *mysqlHostFlag,
MySqlPort: *mysqlPortFlag,
SSOClientID: *ssoClientIDFlag,
SSOClientSecret: *ssoClientSecretFlag,
SSOCallbackURL: *ssoCallbackURLFlag,
SchedulerMemberTracking: *schedulerMemberTrackingFlag,
}
}
return conf, nil
}