本文整理汇总了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)
}
}
示例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))
}
示例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)
}
示例4: main
func main() {
c := Config{}
opts.New(&c).Parse()
fmt.Println(c.Foo)
fmt.Println(c.Bar)
}
示例5: main
func main() {
c := Config{}
opts.New(&c).Parse()
for i, foo := range c.Bazzes {
fmt.Println(i, foo)
}
}
示例6: main
func main() {
c := Config{}
opts.New(&c).
ConfigPath("config.json").
Parse()
fmt.Println(c.Foo)
fmt.Println(c.Bar)
}
示例7: main
func main() {
c := HelpConfig{
Foo: "42",
}
opts.New(&c).
Name("help").
Version("1.0.0").
Repo("https://github.com/jpillora/foo").
Parse()
}
示例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)
}
示例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)
}
示例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)
}
}
示例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())
}
示例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))
}
示例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))
}
示例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)
}
}
示例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))
}