@@ -25,12 +25,13 @@ import (
25
25
type Flags struct {
26
26
DBConn string // database connection string
27
27
Salt string // the salt string used to encode JWT tokens
28
- DBType string // (optional) database type
28
+ DBType string // database type
29
29
SSLCertFile string // (optional) name of SSL certificate PEM file
30
30
SSLKeyFile string // (optional) name of SSL key PEM file
31
31
HTTPPort string // (optional) HTTP or HTTPS port
32
32
ForceHTTPPort2SSL string // (optional) HTTP that should be redirected to HTTPS
33
33
SiteMode string // (optional) if 1 then serve offline web page
34
+ Location string // reserved
34
35
}
35
36
36
37
// SSLEnabled returns true if both cert and key were provided at runtime.
@@ -71,8 +72,9 @@ var flagList progFlags
71
72
var loadMutex sync.Mutex
72
73
73
74
// ParseFlags loads command line and OS environment variables required by the program to function.
74
- func ParseFlags () (f Flags ) {
75
- var dbConn , dbType , jwtKey , siteMode , port , certFile , keyFile , forcePort2SSL string
75
+ func ParseFlags () (f Flags , ok bool ) {
76
+ ok = true
77
+ var dbConn , dbType , jwtKey , siteMode , port , certFile , keyFile , forcePort2SSL , location string
76
78
77
79
register (& jwtKey , "salt" , false , "the salt string used to encode JWT tokens, if not set a random value will be generated" )
78
80
register (& certFile , "cert" , false , "the cert.pem file used for https" )
@@ -82,8 +84,11 @@ func ParseFlags() (f Flags) {
82
84
register (& siteMode , "offline" , false , "set to '1' for OFFLINE mode" )
83
85
register (& dbType , "dbtype" , true , "specify the database provider: mysql|percona|mariadb|postgresql" )
84
86
register (& dbConn , "db" , true , `'database specific connection string for example "user:password@tcp(localhost:3306)/dbname"` )
87
+ register (& location , "location" , false , `reserved` )
85
88
86
- parse ("db" )
89
+ if ! parse ("db" ) {
90
+ ok = false
91
+ }
87
92
88
93
f .DBConn = dbConn
89
94
f .ForceHTTPPort2SSL = forcePort2SSL
@@ -94,7 +99,13 @@ func ParseFlags() (f Flags) {
94
99
f .SSLKeyFile = keyFile
95
100
f .DBType = strings .ToLower (dbType )
96
101
97
- return f
102
+ // reserved
103
+ if len (location ) == 0 {
104
+ location = "selfhost"
105
+ }
106
+ f .Location = strings .ToLower (location )
107
+
108
+ return f , ok
98
109
}
99
110
100
111
// register prepares flag for subsequent parsing
@@ -116,7 +127,7 @@ func register(target *string, name string, required bool, usage string) {
116
127
}
117
128
118
129
// parse loads flags from OS environment and command line switches
119
- func parse (doFirst string ) {
130
+ func parse (doFirst string ) ( ok bool ) {
120
131
loadMutex .Lock ()
121
132
defer loadMutex .Unlock ()
122
133
@@ -141,10 +152,12 @@ func parse(doFirst string) {
141
152
}
142
153
fmt .Fprintln (os .Stderr )
143
154
flag .Usage ()
144
- return
155
+ return false
145
156
}
146
157
}
147
158
}
148
159
}
149
160
}
161
+
162
+ return true
150
163
}
0 commit comments