本文整理匯總了Golang中github.com/wercker/wercker/util.Settings.GlobalString方法的典型用法代碼示例。如果您正苦於以下問題:Golang Settings.GlobalString方法的具體用法?Golang Settings.GlobalString怎麽用?Golang Settings.GlobalString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/wercker/wercker/util.Settings
的用法示例。
在下文中一共展示了Settings.GlobalString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewGlobalOptions
// NewGlobalOptions constructor
func NewGlobalOptions(c util.Settings, e *util.Environment) (*GlobalOptions, error) {
baseURL, _ := c.GlobalString("base-url", DEFAULT_BASE_URL)
baseURL = strings.TrimRight(baseURL, "/")
debug, _ := c.GlobalBool("debug")
journal, _ := c.GlobalBool("journal")
verbose, _ := c.GlobalBool("verbose")
// TODO(termie): switch negative flag
showColors, _ := c.GlobalBool("no-colors")
showColors = !showColors
authTokenStore, _ := c.GlobalString("auth-token-store")
authTokenStore = util.ExpandHomePath(authTokenStore, e.Get("HOME"))
authToken := guessAuthToken(c, e, authTokenStore)
// If debug is true, than force verbose and do not use colors.
if debug {
verbose = true
showColors = false
}
return &GlobalOptions{
BaseURL: baseURL,
Debug: debug,
Journal: journal,
Verbose: verbose,
ShowColors: showColors,
AuthToken: authToken,
AuthTokenStore: authTokenStore,
}, nil
}
示例2: guessAuthToken
// guessAuthToken will attempt to read from the token store location if
// no auth token was provided
func guessAuthToken(c util.Settings, e *util.Environment, authTokenStore string) string {
token, _ := c.GlobalString("auth-token")
if token != "" {
return token
}
if foundToken, _ := util.Exists(authTokenStore); !foundToken {
return ""
}
tokenBytes, err := ioutil.ReadFile(authTokenStore)
if err != nil {
util.RootLogger().WithField("Logger", "Options").Errorln(err)
return ""
}
return strings.TrimSpace(string(tokenBytes))
}