@@ -25,12 +25,13 @@ import (
2525type Flags struct {
2626 DBConn string // database connection string
2727 Salt string // the salt string used to encode JWT tokens
28- DBType string // (optional) database type
28+ DBType string // database type
2929 SSLCertFile string // (optional) name of SSL certificate PEM file
3030 SSLKeyFile string // (optional) name of SSL key PEM file
3131 HTTPPort string // (optional) HTTP or HTTPS port
3232 ForceHTTPPort2SSL string // (optional) HTTP that should be redirected to HTTPS
3333 SiteMode string // (optional) if 1 then serve offline web page
34+ Location string // reserved
3435}
3536
3637// SSLEnabled returns true if both cert and key were provided at runtime.
@@ -71,8 +72,9 @@ var flagList progFlags
7172var loadMutex sync.Mutex
7273
7374// 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
7678
7779 register (& jwtKey , "salt" , false , "the salt string used to encode JWT tokens, if not set a random value will be generated" )
7880 register (& certFile , "cert" , false , "the cert.pem file used for https" )
@@ -82,8 +84,11 @@ func ParseFlags() (f Flags) {
8284 register (& siteMode , "offline" , false , "set to '1' for OFFLINE mode" )
8385 register (& dbType , "dbtype" , true , "specify the database provider: mysql|percona|mariadb|postgresql" )
8486 register (& dbConn , "db" , true , `'database specific connection string for example "user:password@tcp(localhost:3306)/dbname"` )
87+ register (& location , "location" , false , `reserved` )
8588
86- parse ("db" )
89+ if ! parse ("db" ) {
90+ ok = false
91+ }
8792
8893 f .DBConn = dbConn
8994 f .ForceHTTPPort2SSL = forcePort2SSL
@@ -94,7 +99,13 @@ func ParseFlags() (f Flags) {
9499 f .SSLKeyFile = keyFile
95100 f .DBType = strings .ToLower (dbType )
96101
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
98109}
99110
100111// register prepares flag for subsequent parsing
@@ -116,7 +127,7 @@ func register(target *string, name string, required bool, usage string) {
116127}
117128
118129// parse loads flags from OS environment and command line switches
119- func parse (doFirst string ) {
130+ func parse (doFirst string ) ( ok bool ) {
120131 loadMutex .Lock ()
121132 defer loadMutex .Unlock ()
122133
@@ -141,10 +152,12 @@ func parse(doFirst string) {
141152 }
142153 fmt .Fprintln (os .Stderr )
143154 flag .Usage ()
144- return
155+ return false
145156 }
146157 }
147158 }
148159 }
149160 }
161+
162+ return true
150163}
0 commit comments