// Run the command line main(). Note that the client main go program must import the // necessary packages (e.g. import _ pkg/a/b/c) where the packages will register the // module supported by the program. func Main() { buildInfo := version.BuildInfo() flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", buildInfo.Notice()) fmt.Fprintf(os.Stderr, "FLAGS:\n\n") flag.PrintDefaults() fmt.Fprintf(os.Stderr, "MODULES:\n\n") showHelp(os.Stderr) } flag.Parse() buildInfo.HandleFlag() args := flag.Args() if len(args) == 0 { flag.Usage() return } key := args[0] if len(args) > 1 { args = args[1:] } else { args = []string{} } module, has := command.GetModule(key) if !has { fmt.Fprintf(os.Stderr, "%s\n\n", os.Args[0]) showHelp(os.Stderr) return } command.RunModule(key, module, args, os.Stdout) }
func main() { flag.Parse() buildInfo := version.BuildInfo() flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", buildInfo.Notice()) fmt.Fprintf(os.Stderr, "flags:\n") flag.PrintDefaults() } glog.Infoln(buildInfo.Notice()) buildInfo.HandleFlag() // Two server cores running on different ports. Note that quitquitquit will // only shutdown the server requested but no the other one. Kernel signals // will shutdown both. stopped1 := startServer(*port) stopped2 := startServer(*port + 1) for range []int{1, 2} { select { case <-stopped1: case <-stopped2: } } glog.Infoln("Bye") }
func startServer(port int) <-chan error { key := loadPublicKeyFromFile() // For implementing shutdown proxy := make(chan bool) stop, stopped := server.NewService(). WithAuth( server.Auth{ VerifyKeyFunc: func() []byte { return key }, }.Init()). ListenPort(port). Route( server.Endpoint{ UrlRoute: "/info", HttpMethod: server.GET, AuthScope: server.AuthScopeNone, }). To( func(ctx context.Context, resp http.ResponseWriter, req *http.Request) { glog.Infoln("Showing version info.") server.Marshal(resp, req, version.BuildInfo()) }). Route( server.Endpoint{ UrlRoute: "/quitquitquit", HttpMethod: server.POST, AuthScope: server.AuthScope("quitquitquit"), }). To( func(ctx context.Context, resp http.ResponseWriter, req *http.Request) { glog.Infoln("Stopping the server....") proxy <- true }). OnShutdown( func() error { glog.Infoln("Executing user custom shutdown...") return nil }). Start() // For stopping the server go func() { <-proxy stop <- 1 }() return stopped }
func main() { flag.Parse() buildInfo := version.BuildInfo() flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", buildInfo.Notice()) fmt.Fprintf(os.Stderr, "flags:\n") flag.PrintDefaults() } glog.Infoln(buildInfo.Notice()) buildInfo.HandleFlag() stopped := startServer(*port) <-stopped glog.Infoln("Bye") }
func main() { flag.Var(scopes, "A", "Auth scope") flag.Parse() buildInfo := version.BuildInfo() flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", buildInfo.Notice()) fmt.Fprintf(os.Stderr, "flags:\n") flag.PrintDefaults() } buildInfo.HandleFlag() token := auth.NewToken(*ttl) for _, scope := range *scopes { token.Add(scope, 1) } signed, err := token.SignedString(loadPrivateKeyFromFile) MustNot(err) fmt.Print(signed) }