browser-flag: wrapped bool type denotes browser on/off flag. (#3963)

Statically typed BrowserFlag prevents any arbitrary string value
usage. The wrapped bool marshals/unmarshals JSON according to the
typed value ie string value "on" represents boolean true and "off" as
boolean false.
This commit is contained in:
Bala FA
2017-03-27 00:30:27 +05:30
committed by Harshavardhana
parent 565ac4c861
commit 6e63904048
7 changed files with 253 additions and 57 deletions

View File

@@ -96,7 +96,7 @@ func checkUpdate(mode string) {
// envParams holds all env parameters
type envParams struct {
creds credential
browser string
browser BrowserFlag
}
func migrate() {
@@ -139,20 +139,21 @@ func initConfig() {
globalIsEnvCreds = true
}
browser := os.Getenv("MINIO_BROWSER")
if browser != "" {
if !(strings.EqualFold(browser, "off") || strings.EqualFold(browser, "on")) {
fatalIf(errors.New("invalid value"), "%s in MINIO_BROWSER environment variable.", browser)
}
// browser Envs are set globally, this doesn't represent
// if browser is turned off or on.
globalIsEnvBrowser = true
}
envs := envParams{
creds: cred,
browser: browser,
browser: BrowserFlag(true),
}
if browser := os.Getenv("MINIO_BROWSER"); browser != "" {
browserFlag, err := ParseBrowserFlag(browser)
if err != nil {
fatalIf(errors.New("invalid value"), "Unknown value %s in MINIO_BROWSER environment variable.", browser)
}
// browser Envs are set globally, this does not represent
// if browser is turned off or on.
globalIsEnvBrowser = true
envs.browser = browserFlag
}
// Config file does not exist, we create it fresh and return upon success.