本文整理匯總了Golang中github.com/wercker/wercker/util.Environment.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Environment.Get方法的具體用法?Golang Environment.Get怎麽用?Golang Environment.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/wercker/wercker/util.Environment
的用法示例。
在下文中一共展示了Environment.Get方法的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: guessAndUpdateDockerOptions
func guessAndUpdateDockerOptions(opts *DockerOptions, e *util.Environment) {
if opts.DockerHost != "" {
return
}
logger := util.RootLogger().WithField("Logger", "docker")
// f := &util.Formatter{opts.GlobalOptions.ShowColors}
f := &util.Formatter{false}
// Check the unix socket, default on linux
// This will fail instantly so don't bother with the goroutine
unixSocket := "/var/run/docker.sock"
logger.Println(f.Info("No Docker host specified, checking", unixSocket))
if _, err := os.Stat(unixSocket); err == nil {
unixSocket = fmt.Sprintf("unix://%s", unixSocket)
client, err := NewDockerClient(&DockerOptions{
DockerHost: unixSocket,
})
if err == nil {
_, err = client.Version()
if err == nil {
opts.DockerHost = unixSocket
return
}
}
}
// Check the boot2docker port with default cert paths and such
b2dCertPath := filepath.Join(e.Get("HOME"), ".boot2docker/certs/boot2docker-vm")
b2dHost := "tcp://192.168.59.103:2376"
logger.Printf(f.Info("No Docker host specified, checking for boot2docker", b2dHost))
client, err := NewDockerClient(&DockerOptions{
DockerHost: b2dHost,
DockerCertPath: b2dCertPath,
DockerTLSVerify: "1",
})
if err == nil {
// This can take a long time if it isn't up, so toss it in a
// goroutine so we can time it out
result := make(chan bool)
go func() {
_, err = client.Version()
if err == nil {
result <- true
} else {
result <- false
}
}()
select {
case success := <-result:
if success {
opts.DockerHost = b2dHost
opts.DockerCertPath = b2dCertPath
opts.DockerTLSVerify = "1"
return
}
case <-time.After(1 * time.Second):
}
}
// Pick a default localhost port and hope for the best :/
opts.DockerHost = "tcp://127.0.0.1:2375"
logger.Println(f.Info("No Docker host found, falling back to default", opts.DockerHost))
}