package cmd import ( "axolotl/serve" "axolotl/service" "fmt" "net/http" "os" "github.com/spf13/cobra" ) var serveCmd = &cobra.Command{ Use: "serve", Short: "Start the JSON API server", Run: func(cmd *cobra.Command, args []string) { sc := cfg.GetServerConfig() addr := fmt.Sprintf("%s:%d", sc.Host, sc.Port) handler := serve.New(service.GetNodeServiceForUser) fmt.Fprintf(os.Stdout, "listening on %s\n", addr) if err := http.ListenAndServe(addr, handler); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }, } func init() { rootCmd.AddCommand(serveCmd) }