本文整理汇总了Golang中flag.Parse函数的典型用法代码示例。如果您正苦于以下问题:Golang Parse函数的具体用法?Golang Parse怎么用?Golang Parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Parse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
certpath := flag.String("cert", "", "The path to a PEM certificate")
keypath := flag.String("key", "", "The path to a PEM key")
flag.Parse()
if len(*certpath) == 0 || len(*keypath) == 0 {
flag.PrintDefaults()
return
}
ctx := gossl.NewContext(gossl.SSLv3Method())
ctx.SetOptions(gossl.OpNoCompression)
err := ctx.UsePrivateKeyFile(*keypath, gossl.FileTypePem)
if err != nil {
panic(err)
}
ctx.UseCertificateFile(*certpath, gossl.FileTypePem)
if err != nil {
panic(err)
}
l, err := net.Listen("tcp", ":8000")
if err != nil {
panic(err)
}
l, err = gossl.NewListener(l, ctx)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q\n", html.EscapeString(r.URL.Path))
})
http.Serve(l, nil)
}
开发者ID:runcom,项目名称:gossl,代码行数:29,代码来源:httpserver.go
示例2: main
func main() {
flag.Parse()
grpc.EnableTracing = true
flag.Parse()
lis, err := net.Listen("tcp", *port)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
grpcServer := grpc.NewServer()
var downstreamClients []pb.PingClient
for _, d := range strings.Split(*downstreams, ",") {
if d == "" {
continue
}
log.Println(d)
conn, err := grpc.Dial(d, grpc.WithBlock())
if err != nil {
log.Fatalf("In here " + err.Error())
}
defer conn.Close()
downstreamClients = append(downstreamClients, pb.NewPingClient(conn))
}
pb.RegisterPingServer(grpcServer, &pingServer{downstreams: downstreamClients})
go grpcServer.Serve(lis)
log.Fatal(http.ListenAndServe(*httpPort, nil))
}
开发者ID:tcolgate,项目名称:test,代码行数:32,代码来源:main.go
示例3: main
func main() {
if e := os.Getenv("DOOZER_URI"); e != "" {
*uri = e
}
if e := os.Getenv("DOOZER_BOOT_URI"); e != "" {
*buri = e
}
flag.Usage = usage
flag.Parse()
if *showHelp {
usage()
return
}
if *showVersion {
fmt.Println("doozer", version)
return
}
if flag.NArg() < 1 {
fmt.Fprintf(os.Stderr, "%s: missing command\n", os.Args[0])
usage()
os.Exit(127)
}
cmd := flag.Arg(0)
c, ok := cmds[cmd]
if !ok {
fmt.Fprintln(os.Stderr, "Unknown command:", cmd)
usage()
os.Exit(127)
}
os.Args = flag.Args()
flag.Parse()
if *showHelp {
help(cmd)
return
}
args := flag.Args()
ft := reflect.TypeOf(c.f)
if len(args) != ft.NumIn() {
fmt.Fprintf(os.Stderr, "%s: wrong number of arguments\n", cmd)
help(cmd)
os.Exit(127)
}
vals := make([]reflect.Value, len(args))
for i, s := range args {
vals[i] = reflect.ValueOf(s)
}
fv := reflect.ValueOf(c.f)
fv.Call(vals)
}
开发者ID:musicglue,项目名称:doozer,代码行数:60,代码来源:doozer.go
示例4: main
func main() {
logger := log.NewLogger()
cfg := config.Default()
flag.StringVar(&cfg.WSAddress, "ws", cfg.WSAddress, "Websocket address")
flag.StringVar(&cfg.RESTAddress, "rest", cfg.RESTAddress, "REST address")
flag.StringVar(&cfg.Origin, "o", cfg.Origin, "Origin URL")
file := flag.String("config", "", "Config file")
flag.Parse()
if *file != "" {
err := config.FromFile(*file, &cfg)
if err != nil {
logger.Err.Fatal(err)
}
flag.Parse()
}
broker := pubsub.NewBroker()
go func() {
wsRouter := mux.NewRouter()
wsRouter.Handle("/{id}", handlers.WSHandler{Broker: broker, Config: cfg, Logger: logger})
logger.Out.Println("Listening websockets on", cfg.WSAddress)
logger.Err.Fatal(http.ListenAndServe(cfg.WSAddress, wsRouter))
}()
go func() {
restRouter := mux.NewRouter()
restRouter.Handle("/topic", handlers.List{Broker: broker, Logger: logger}).Methods("GET")
restRouter.Handle("/topic", handlers.Add{Broker: broker, Logger: logger}).Methods("POST")
restRouter.Handle("/topic/{id}", handlers.Pub{Broker: broker, Logger: logger}).Methods("POST")
restRouter.Handle("/topic/{id}", handlers.Del{Broker: broker, Logger: logger}).Methods("DELETE")
restRouter.Handle("/ping", handlers.Ping{Logger: logger}).Methods("GET")
logger.Out.Println("Listening REST on", cfg.RESTAddress)
logger.Err.Fatal(http.ListenAndServe(cfg.RESTAddress, restRouter))
}()
wait := make(chan struct{})
<-wait
}
开发者ID:arvinkulagin,项目名称:beeper,代码行数:35,代码来源:main.go
示例5: main
func main() {
var action string
// rewrite arguments so that we can support multiple "actions" in a single binary
newArgs := make([]string, 0, len(os.Args))
for i, arg := range os.Args {
if i > 0 && arg[0] != '-' && action == "" {
action = arg
continue
}
newArgs = append(newArgs, arg)
}
os.Args = newArgs
if action == "" {
fmt.Fprintln(os.Stderr, "Error: action was not specified")
dieWithUsage()
}
if action == ACTION_LOGS_COLLECTOR {
logscol.InitFlags()
flag.Parse()
logscol.Run()
return
} else if action == ACTION_LOGS_PROCESSOR {
logsproc.InitFlags()
flag.Parse()
logsproc.Run()
return
}
dieWithUsage()
}
开发者ID:kshvakov,项目名称:thunder,代码行数:34,代码来源:main.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng