本文整理汇总了Golang中github.com/urfave/cli.Context.GlobalDuration方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GlobalDuration方法的具体用法?Golang Context.GlobalDuration怎么用?Golang Context.GlobalDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/urfave/cli.Context
的用法示例。
在下文中一共展示了Context.GlobalDuration方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getTransport
func getTransport(c *cli.Context) (*http.Transport, error) {
cafile := c.GlobalString("ca-file")
certfile := c.GlobalString("cert-file")
keyfile := c.GlobalString("key-file")
// Use an environment variable if nothing was supplied on the
// command line
if cafile == "" {
cafile = os.Getenv("ETCDCTL_CA_FILE")
}
if certfile == "" {
certfile = os.Getenv("ETCDCTL_CERT_FILE")
}
if keyfile == "" {
keyfile = os.Getenv("ETCDCTL_KEY_FILE")
}
tls := transport.TLSInfo{
CAFile: cafile,
CertFile: certfile,
KeyFile: keyfile,
}
dialTimeout := defaultDialTimeout
totalTimeout := c.GlobalDuration("total-timeout")
if totalTimeout != 0 && totalTimeout < dialTimeout {
dialTimeout = totalTimeout
}
return transport.NewTransport(tls, dialTimeout)
}
示例2: newClient
func newClient(c *cli.Context) (client.Client, error) {
eps, err := getEndpoints(c)
if err != nil {
return nil, err
}
tr, err := getTransport(c)
if err != nil {
return nil, err
}
cfg := client.Config{
Transport: tr,
Endpoints: eps,
HeaderTimeoutPerRequest: c.GlobalDuration("timeout"),
}
uFlag := c.GlobalString("username")
if uFlag == "" {
uFlag = os.Getenv("ETCDCTL_USERNAME")
}
if uFlag != "" {
username, password, err := getUsernamePasswordFromFlag(uFlag)
if err != nil {
return nil, err
}
cfg.Username = username
cfg.Password = password
}
return client.New(cfg)
}
示例3: etcdConfigFromFlags
func etcdConfigFromFlags(c *cli.Context) etcdclient.Config {
eFlag := c.GlobalString("endpoint")
uFlag := c.GlobalString("username")
pFlag := c.GlobalString("password")
tFlag := c.GlobalDuration("timeout")
cfg := etcdclient.Config{
Endpoints: strings.Split(eFlag, ","),
Transport: etcdclient.DefaultTransport,
HeaderTimeoutPerRequest: tFlag,
}
if uFlag != "" && pFlag != "" {
cfg.Username = uFlag
cfg.Password = pFlag
}
return cfg
}
示例4: contextWithTotalTimeout
func contextWithTotalTimeout(c *cli.Context) (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), c.GlobalDuration("total-timeout"))
}