• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang opts.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/jpillora/opts.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	opts.New(&c).Repo("github.com/jpillora/installer").Version(VERSION).Parse()
	log.Printf("Default user is '%s' and listening on %d...", c.User, c.Port)
	if err := http.ListenAndServe(":"+strconv.Itoa(c.Port), http.HandlerFunc(install)); err != nil {
		log.Fatal(err)
	}
}
开发者ID:jpillora,项目名称:installer,代码行数:7,代码来源:main.go


示例2: main

func main() {

	c := config{
		Host: "0.0.0.0",
		Port: 3000,
	}

	opts.New(&c).
		Repo("github.com/jpillora/scraper").
		Version(VERSION).
		Parse()

	h := &scraper.Handler{Log: true}

	go func() {
		for {
			sig := make(chan os.Signal, 1)
			signal.Notify(sig, syscall.SIGHUP)
			<-sig
			if err := h.LoadConfigFile(c.ConfigFile); err != nil {
				log.Printf("failed to load configuration: %s", err)
			} else {
				log.Printf("successfully loaded new configuration")
			}
		}
	}()

	if err := h.LoadConfigFile(c.ConfigFile); err != nil {
		log.Fatal(err)
	}

	log.Printf("listening on %d...", c.Port)
	log.Fatal(http.ListenAndServe(c.Host+":"+strconv.Itoa(c.Port), h))
}
开发者ID:voxadam,项目名称:scraper,代码行数:34,代码来源:main.go


示例3: main

func main() {
	c := Config{}
	//In this case UseEnv() is equivalent to
	//adding `env:"FOO"` and `env:"BAR"` tags
	opts.New(&c).UseEnv().Parse()
	fmt.Println(c.Foo)
	fmt.Println(c.Bar)
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:8,代码来源:env.go


示例4: main

func main() {

	c := Config{}

	opts.New(&c).Parse()

	fmt.Println(c.Foo)
	fmt.Println(c.Bar)
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:9,代码来源:arg.go


示例5: main

func main() {

	c := Config{}

	opts.New(&c).Parse()

	for i, foo := range c.Bazzes {
		fmt.Println(i, foo)
	}
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:10,代码来源:args.go


示例6: main

func main() {

	c := Config{}

	opts.New(&c).
		ConfigPath("config.json").
		Parse()

	fmt.Println(c.Foo)
	fmt.Println(c.Bar)
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:11,代码来源:config.go


示例7: main

func main() {

	c := HelpConfig{
		Foo: "42",
	}

	opts.New(&c).
		Name("help").
		Version("1.0.0").
		Repo("https://github.com/jpillora/foo").
		Parse()
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:12,代码来源:help.go


示例8: main

func main() {

	c := Config2{}

	//UseEnv() essentially adds an `env` tag on all fields,
	//infering the env var name from the field name.
	//Specifically adding the `env` tag will only enable it
	//for a single field.
	opts.New(&c).Parse()

	fmt.Println(c.Foo)
	fmt.Println(c.Bar)
}
开发者ID:pmwoodward3,项目名称:torrentsaga,代码行数:13,代码来源:env_one.go


示例9: main

func main() {

	c := &daemon.Config{
		Interval: 30 * time.Second,
	}

	opts.New(c).
		Version("0.2.0").
		PkgRepo().
		Parse()

	log.SetOutput(os.Stderr)
	daemon.Run(*c)
}
开发者ID:postfix,项目名称:whos-home,代码行数:14,代码来源:main.go


示例10: main

func main() {
	s := ct.Server{
		Port: 3000,
	}

	opts.New(&s).
		Version(VERSION).
		PkgRepo().
		Parse()

	if err := s.Run(); err != nil {
		log.Fatal(err)
	}
}
开发者ID:prithi,项目名称:cloud-torrent,代码行数:14,代码来源:main.go


示例11: main

func main() {

	c := Config{}

	//see default templates and the default template order
	//in the opts/help.go file
	o := opts.New(&c).
		DocAfter("usage", "mytext", "\nthis is a some text!\n"). //add new entry
		Repo("myfoo.com/bar").
		DocSet("repo", "\nMy awesome repo:\n  {{.Repo}}"). //change existing entry
		Parse()

	fmt.Println(o.Help())
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:14,代码来源:customhelp.go


示例12: main

func main() {
	c := config{Port: 3000, Config: podsling.Config{Log: true}}
	opts.New(&c).
		Version(VERSION).
		Repo("github.com/jpillora/podsling").
		Parse()

	h, err := podsling.NewHandler(c.Config)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Listening on %d...", c.Port)
	log.Fatal(http.ListenAndServe(":"+strconv.Itoa(c.Port), h))
}
开发者ID:jpillora,项目名称:podsling,代码行数:15,代码来源:podsling.go


示例13: main

func main() {
	a := App{
		Handler: &webfontdownloader.Handler{},
		Port:    3000,
	}

	opts.
		New(&a).
		Version(VERSION).
		Repo("github.com/jpillora/webfont-downloader").
		Parse()

	log.Printf("Listening on %d...", a.Port)
	log.Fatal(http.ListenAndServe(":"+strconv.Itoa(a.Port), a.Handler))
}
开发者ID:jpillora,项目名称:webfont-downloader,代码行数:15,代码来源:server.go


示例14: main

func main() {
	s := server.Server{
		Port:       3000,
		ConfigPath: "cloud-torrent.json",
	}

	opts.New(&s).
		Version(VERSION).
		PkgRepo().
		Parse()

	if err := s.Run(VERSION); err != nil {
		log.Fatal(err)
	}
}
开发者ID:fieryrain,项目名称:cloud-torrent,代码行数:15,代码来源:main.go


示例15: main

func main() {
	c := struct {
		Port        int `help:"Port" env:"PORT"`
		echo.Config `type:"embedded"`
	}{
		Port: 3000,
	}
	opts.New(&c).
		Name("go-echo-server").
		Version(VERSION).
		Repo("github.com/jpillora/go-echo-server").
		Parse()

	h := echo.New(c.Config)
	log.Printf("Listening on %d...", c.Port)
	log.Fatal(http.ListenAndServe(":"+strconv.Itoa(c.Port), h))
}
开发者ID:jpillora,项目名称:go-echo-server,代码行数:17,代码来源:main.go


示例16: main

func main() {
	s := server.Server{
		Title:      "Cloud Torrent",
		Port:       9000,
		ConfigPath: "cloud-torrent.json",
	}

	o := opts.New(&s)
	o.Version(VERSION)
	o.PkgRepo()
	o.LineWidth = 96
	o.Parse()

	if err := s.Run(VERSION); err != nil {
		log.Fatal(err)
	}
}
开发者ID:Zarloc,项目名称:cloud-torrent,代码行数:17,代码来源:main.go


示例17: main

func main() {
	s := server.Server{
		Title:      "TorrentSaga",
		Port:       3000,
		ConfigPath: "settings.json",
	}

	o := opts.New(&s)
	o.Version(VERSION)
	o.PkgRepo()
	o.LineWidth = 96
	o.Parse()

	if err := s.Run(VERSION); err != nil {
		log.Fatal(err)
	}
}
开发者ID:jaswinder-singh,项目名称:torrentsaga,代码行数:17,代码来源:main.go


示例18: main

func main() {

	//defaults
	c := Config{
		Host: "0.0.0.0",
		Port: 3000,
		Config: serve.Config{
			Directory: ".",
		},
	}

	//parse
	opts.New(&c).
		Name("serve").
		Version(VERSION).
		Repo("github.com/jpillora/serve").
		Parse()

	//ready!
	h, err := serve.NewHandler(c.Config)
	if err != nil {
		log.Fatal(err)
	}

	port := strconv.Itoa(c.Port)

	if c.Open {
		go func() {
			time.Sleep(500 * time.Millisecond)
			cmd := exec.Command("open", "http://localhost:"+port)
			cmd.Run()
		}()
	}

	fmt.Printf("%sserving %s%s %son port %s%d%s\n",
		requestlog.DefaultOptions.Colors.Grey,
		requestlog.DefaultOptions.Colors.Cyan, c.Config.Directory,
		requestlog.DefaultOptions.Colors.Grey,
		requestlog.DefaultOptions.Colors.Cyan, c.Port,
		requestlog.DefaultOptions.Colors.Reset,
	)

	log.Fatal(http.ListenAndServe(":"+port, h))
}
开发者ID:jmcarbo,项目名称:serve,代码行数:44,代码来源:main.go


示例19: main

func main() {
	//cli config
	config := struct {
		Port            int `help:"listening port"`
		uploader.Config `type:"embedded"`
	}{
		Port:   3000,
		Config: uploader.Config{Dir: "."},
	}

	opts.New(&config).
		Name("uploader").
		Repo("github.com/jpillora/uploader").
		Version(VERSION).
		Parse()

	log.Printf("listening on %d...", config.Port)
	http.ListenAndServe(fmt.Sprintf(":%d", config.Port), uploader.New(config.Config))
}
开发者ID:jpillora,项目名称:uploader,代码行数:19,代码来源:main.go


示例20: main

func main() {
	//configuration with defaults
	c := lib.Config{
		Ping: "!",
		Pong: "?",
	}
	//parse config, note the library version, and extract the
	//repository link from the config package import path
	opts.New(&c).
		Name("foo"). //explicitly name (otherwise it will use the project name from the pkg import path)
		Version(VERSION).
		PkgRepo().
		Parse()
	//construct a foo
	foo, err := lib.NewFoo(c)
	if err != nil {
		log.Fatal(err)
	}
	//ready! run foo!
	foo.Run()
}
开发者ID:pmwoodward3,项目名称:torrentsaga,代码行数:21,代码来源:main.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gortlsdr.Context类代码示例发布时间:2022-05-23
下一篇:
Golang archive.Archive类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap