本文整理汇总了Golang中github.com/codegangsta/cli.Context.GlobalDuration方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GlobalDuration方法的具体用法?Golang Context.GlobalDuration怎么用?Golang Context.GlobalDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.GlobalDuration方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: processGlobalFlags
func processGlobalFlags(c *cli.Context) time.Duration {
var network string
if c.GlobalBool("tcp") {
network = "tcp"
} else {
network = "udp"
}
client, err := raidman.Dial(network, fmt.Sprintf("%s:%d", c.GlobalString("host"), c.GlobalInt("port")))
if c.GlobalString("event-host") == "nil" {
log.Panic("Failed to automatically get the hostname. Please specify it with --host")
}
if err != nil {
log.Panicf("Failed to connect to the riemann host because %s", err)
}
attribute, err := processAttributes(c.GlobalStringSlice("attribute"))
if err != nil {
log.Panic(err)
}
eventTemplate := raidman.Event{
Ttl: float32(c.GlobalDuration("ttl").Seconds()),
Tags: c.GlobalStringSlice("tags"),
Host: c.GlobalString("event-host"),
Attributes: attribute,
}
riemannSend = func(url, method string, duration float64) {
event := eventTemplate
event.Service = fmt.Sprintf("%s %s", url, method)
event.Time = time.Now().Unix()
event.Metric = duration
client.Send(&event)
}
return c.GlobalDuration("interval")
}
示例3: 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)
}
示例4: getClient
// TODO: parse flags and pass opts
func getClient(ctx *cli.Context) types.APIClient {
// reset the logger for grpc to log to dev/null so that it does not mess with our stdio
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
dialOpts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(ctx.GlobalDuration("conn-timeout"))}
dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
},
))
conn, err := grpc.Dial(ctx.GlobalString("address"), dialOpts...)
if err != nil {
fatal(err.Error(), 1)
}
return types.NewAPIClient(conn)
}
示例5: actionMain
func actionMain(c *cli.Context) {
if !c.GlobalIsSet("url") || !c.GlobalIsSet("ref") {
log.Fatalln("Error: --url and --ref required")
}
where, err := git.PrepBuildDirectory(
c.GlobalString("destination"),
c.GlobalString("url"),
c.GlobalString("ref"),
c.GlobalDuration("timeout"),
os.Stderr)
if err != nil {
log.Fatalln("Error:", err)
}
log.Printf("Checked out %v at %v", where.Name, where.Dir)
fmt.Println(where.Dir)
}
示例6: 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
}
示例7: getClient
// TODO: parse flags and pass opts
func getClient(ctx *cli.Context) types.APIClient {
// Parse proto://address form addresses.
bindSpec := ctx.GlobalString("address")
bindParts := strings.SplitN(bindSpec, "://", 2)
if len(bindParts) != 2 {
fatal(fmt.Sprintf("bad bind address format %s, expected proto://address", bindSpec), 1)
}
// reset the logger for grpc to log to dev/null so that it does not mess with our stdio
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
dialOpts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(ctx.GlobalDuration("conn-timeout"))}
dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout(bindParts[0], bindParts[1], timeout)
},
))
conn, err := grpc.Dial(bindSpec, dialOpts...)
if err != nil {
fatal(err.Error(), 1)
}
return types.NewAPIClient(conn)
}
示例8: loadConfig
func loadConfig(c *cli.Context) Etcdtool {
// Enable debug
if c.GlobalBool("debug") {
debug = true
}
// Default path for config file.
u, _ := user.Current()
cfgs := []string{
"/etcd/etcdtool.json",
"/etcd/etcdtool.yaml",
"/etcd/etcdtool.toml",
u.HomeDir + "/.etcdtool.json",
u.HomeDir + "/.etcdtool.yaml",
u.HomeDir + "/.etcdtool.toml",
}
// Check if we have an arg. for config file and that it exist's.
if c.GlobalString("config") != "" {
if _, err := os.Stat(c.GlobalString("config")); os.IsNotExist(err) {
fatalf("Config file doesn't exist: %s", c.GlobalString("config"))
}
cfgs = append([]string{c.GlobalString("config")}, cfgs...)
}
// Check if config file exists and load it.
e := Etcdtool{}
for _, fn := range cfgs {
if _, err := os.Stat(fn); os.IsNotExist(err) {
continue
}
infof("Using config file: %s", fn)
f, err := iodatafmt.FileFormat(fn)
if err != nil {
fatal(err.Error())
}
if err := iodatafmt.LoadPtr(&e, fn, f); err != nil {
fatal(err.Error())
}
}
// Override with arguments or env. variables.
if c.GlobalString("peers") != "" {
e.Peers = c.GlobalString("peers")
}
if c.GlobalString("cert") != "" {
e.Cert = c.GlobalString("cert")
}
if c.GlobalString("key") != "" {
e.Key = c.GlobalString("key")
}
if c.GlobalString("ca") != "" {
e.CA = c.GlobalString("ca")
}
if c.GlobalString("user") != "" {
e.User = c.GlobalString("user")
}
if c.GlobalDuration("timeout") != 0 {
e.Timeout = c.GlobalDuration("timeout")
}
if c.GlobalDuration("command-timeout") != 0 {
e.CommandTimeout = c.GlobalDuration("command-timeout")
}
return e
}
示例9: Load
//.........这里部分代码省略.........
"/app/etc/etcdrest.tml",
}
// Check if we have an arg. for config file and that it exist's.
if c.GlobalString("config") != "" {
if _, err := os.Stat(c.GlobalString("config")); os.IsNotExist(err) {
log.Fatalf("Config file doesn't exist: %s", c.GlobalString("config"))
}
cfgs = append([]string{c.GlobalString("config")}, cfgs...)
}
for _, fn := range cfgs {
if _, err := os.Stat(fn); os.IsNotExist(err) {
continue
}
log.Infof("Using config file: %s", fn)
// Load config file.
b, err := ioutil.ReadFile(fn)
if err != nil {
log.Fatal(err.Error())
}
switch filepath.Ext(fn) {
case ".json":
if err := json.Unmarshal(b, cfg); err != nil {
log.Fatal(err.Error())
}
case ".yaml", ".yml":
if err := yaml.Unmarshal(b, cfg); err != nil {
log.Fatal(err.Error())
}
case ".toml", ".tml":
if err := toml.Unmarshal(b, cfg); err != nil {
log.Fatal(err.Error())
}
default:
log.Fatal("unsupported data format")
}
// Validate config using JSON schema.
break
}
// Override configuration.
if c.GlobalString("templ-dir") != "" {
cfg.TemplDir = c.GlobalString("templ-dir")
}
if c.GlobalString("schema-uri") != "" {
cfg.SchemaURI = c.GlobalString("schema-uri")
}
if c.GlobalString("bind") != "" {
cfg.Bind = c.GlobalString("bind")
}
if c.GlobalString("server-uri") != "" {
cfg.ServerURI = c.GlobalString("server-uri")
}
if c.GlobalBool("envelope") {
cfg.Envelope = true
}
if c.GlobalBool("no-indent") {
cfg.Indent = true
}
// Override etcd configuration.
if c.GlobalString("peers") != "" {
cfg.Etcd.Peers = c.GlobalString("peers")
}
if c.GlobalString("cert") != "" {
cfg.Etcd.Cert = c.GlobalString("cert")
}
if c.GlobalString("key") != "" {
cfg.Etcd.Key = c.GlobalString("key")
}
if c.GlobalString("ca") != "" {
cfg.Etcd.CA = c.GlobalString("ca")
}
if c.GlobalString("user") != "" {
cfg.Etcd.User = c.GlobalString("user")
}
if c.GlobalDuration("timeout") != 0 {
cfg.Etcd.Timeout = c.GlobalDuration("timeout")
}
if c.GlobalDuration("command-timeout") != 0 {
cfg.Etcd.CmdTimeout = c.GlobalDuration("command-timeout")
}
}
示例10: contextWithTotalTimeout
func contextWithTotalTimeout(c *cli.Context) (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), c.GlobalDuration("total-timeout"))
}
示例11: contextWithCommandTimeout
func contextWithCommandTimeout(c *cli.Context) (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), c.GlobalDuration("command-timeout"))
}