本文整理汇总了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))
}