func main() { config := &skynet.ClientConfig{ DoozerConfig: &skynet.DoozerConfig{}, } flagset := flag.NewFlagSet("sleepclient", flag.ContinueOnError) skynet.FlagsForClient(config, flagset) req := sleeper.Request{ Message: "Hello!", } var ( retry time.Duration giveup time.Duration ) flagset.DurationVar(&req.Duration, "sleepfor", 5*time.Second, "how long to sleep") flagset.BoolVar(&req.ExitWhenDone, "exit", false, "have the service call os.Exit(0) when finished sleeping") flagset.BoolVar(&req.PanicWhenDone, "panic", false, "have the service panic when finished sleeping") flagset.BoolVar(&req.UnregisterWhenDone, "unregister", false, "have the service unregister when finished sleeping") flagset.BoolVar(&req.UnregisterHalfwayThrough, "unregister-halfway", false, "have the service unregister half-way through the sleep") flagset.DurationVar(&retry, "retry", time.Second, "how long to wait before trying again") flagset.DurationVar(&giveup, "giveup", 5*time.Second, "how long to wait before giving up") flagset.Parse(os.Args[1:]) config.MaxConnectionsToInstance = 5 client := client.NewClient(config) service := client.GetService("Sleeper", "", "", "") service.SetTimeout(retry, giveup) resp := sleeper.Response{} start := time.Now() err := service.Send(nil, "Sleep", req, &resp) duration := time.Now().Sub(start).Nanoseconds() fmt.Printf("request took %dns\n", duration) if err != nil { fmt.Println(err) } else { fmt.Printf("%s -> %s\n", req.Message, resp.Message) } }
func main() { logger := skynet.NewConsoleSemanticLogger("Sky", os.Stdout) config = skynet.ClientConfig{ DoozerConfig: &skynet.DoozerConfig{}, Log: logger, } skynet.FlagsForClient(&config, flagset) err := flagset.Parse(os.Args[1:]) if err != nil { fmt.Println(err) return } query := &skynet.Query{ DoozerConn: Doozer(config.DoozerConfig), Service: *ServiceNameFlag, Version: *VersionFlag, Host: *HostFlag, Region: config.Region, Port: *PortFlag, } fmt.Println(flagset.Args()) switch flagset.Arg(0) { case "help", "h": CommandLineHelp() case "services": ListServices(query) case "hosts": ListHosts(query) case "regions": ListRegions(query) case "instances": ListInstances(query) case "versions": ListServiceVersions(query) case "topology": PrintTopology(query) case "register": Register(query) case "unregister": Unregister(query) case "stop": Stop(query) case "restart": Restart(query) case "deploy": args := flagset.Args() fmt.Println(args) if len(args) < 2 { fmt.Println("Usage: deploy <service path> <args>") return } Deploy(query, args[1], args[2:]...) case "cli": InteractiveShell() default: CommandLineHelp() } }