当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.GlobalDuration方法代码示例

本文整理汇总了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)
}
开发者ID:luxas,项目名称:flannel,代码行数:34,代码来源:util.go

示例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")
}
开发者ID:larue3000,项目名称:riemann-ping,代码行数:34,代码来源:ping.go

示例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)
}
开发者ID:XiangrongFan,项目名称:etcd,代码行数:30,代码来源:util.go

示例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)
}
开发者ID:carriercomm,项目名称:containerd,代码行数:16,代码来源:container.go

示例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)
}
开发者ID:scraperwiki,项目名称:git-prep-directory,代码行数:17,代码来源:main.go

示例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
}
开发者ID:leobcn,项目名称:gru,代码行数:19,代码来源:utils.go

示例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)
}
开发者ID:estesp,项目名称:containerd,代码行数:23,代码来源:container.go

示例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
}
开发者ID:mickep76,项目名称:etcdtool,代码行数:72,代码来源:config.go

示例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")
	}
}
开发者ID:mickep76,项目名称:etcdrest,代码行数:101,代码来源:config.go

示例10: contextWithTotalTimeout

func contextWithTotalTimeout(c *cli.Context) (context.Context, context.CancelFunc) {
	return context.WithTimeout(context.Background(), c.GlobalDuration("total-timeout"))
}
开发者ID:luxas,项目名称:flannel,代码行数:3,代码来源:util.go

示例11: contextWithCommandTimeout

func contextWithCommandTimeout(c *cli.Context) (context.Context, context.CancelFunc) {
	return context.WithTimeout(context.Background(), c.GlobalDuration("command-timeout"))
}
开发者ID:mickep76,项目名称:etcdtool,代码行数:3,代码来源:connect.go


注:本文中的github.com/codegangsta/cli.Context.GlobalDuration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。