當前位置: 首頁>>代碼示例>>Golang>>正文


Golang opts.New函數代碼示例

本文整理匯總了Golang中github.com/jpillora/opts.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/jpillora/opts.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。