本文整理汇总了Golang中github.com/coreos/etcdctl/third_party/github.com/codegangsta/cli.Context.GlobalStringSlice方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GlobalStringSlice方法的具体用法?Golang Context.GlobalStringSlice怎么用?Golang Context.GlobalStringSlice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/etcdctl/third_party/github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.GlobalStringSlice方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: rawhandle
// rawhandle wraps the command function handlers and sets up the
// environment but performs no output formatting.
func rawhandle(c *cli.Context, fn handlerFunc) (*etcd.Response, error) {
sync := !c.GlobalBool("no-sync")
peers := c.GlobalStringSlice("peers")
// Append default peer address if not any
if len(peers) == 0 {
peers_from_environment := os.Getenv("ETCDCTL_PEERS")
if peers_from_environment != "" {
peers = strings.Split(peers_from_environment, ",")
} else {
peers = append(peers, "127.0.0.1:4001")
}
}
// If no sync, create http path for each peer address
if !sync {
revisedPeers := make([]string, 0)
for _, peer := range peers {
if revisedPeer, err := createHttpPath(peer); err != nil {
fmt.Fprintf(os.Stderr, "Unsupported url %v: %v\n", peer, err)
} else {
revisedPeers = append(revisedPeers, revisedPeer)
}
}
peers = revisedPeers
}
client := etcd.NewClient(peers)
if c.GlobalBool("debug") {
go dumpCURL(client)
}
// Sync cluster.
if sync {
if ok := client.SyncCluster(); !ok {
handleError(FailedToConnectToHost, errors.New("Cannot sync with the cluster using peers "+strings.Join(peers, ", ")))
}
}
if c.GlobalBool("debug") {
fmt.Fprintf(os.Stderr, "Cluster-Peers: %s\n",
strings.Join(client.GetCluster(), " "))
}
// Execute handler function.
return fn(c, client)
}