github.com/dhax/go-base@v0.0.0-20231004214136-8be7e5c1972b/cmd/serve.go (about) 1 package cmd 2 3 import ( 4 "log" 5 6 "github.com/dhax/go-base/api" 7 "github.com/spf13/cobra" 8 "github.com/spf13/viper" 9 ) 10 11 // serveCmd represents the serve command 12 var serveCmd = &cobra.Command{ 13 Use: "serve", 14 Short: "start http server with configured api", 15 Long: `Starts a http server and serves the configured api`, 16 Run: func(cmd *cobra.Command, args []string) { 17 server, err := api.NewServer() 18 if err != nil { 19 log.Fatal(err) 20 } 21 server.Start() 22 }, 23 } 24 25 func init() { 26 RootCmd.AddCommand(serveCmd) 27 28 // Here you will define your flags and configuration settings. 29 viper.SetDefault("port", "3000") 30 viper.SetDefault("log_level", "debug") 31 32 viper.SetDefault("auth_login_url", "http://localhost:3000/login") 33 viper.SetDefault("auth_login_token_length", 8) 34 viper.SetDefault("auth_login_token_expiry", "11m") 35 viper.SetDefault("auth_jwt_secret", "random") 36 viper.SetDefault("auth_jwt_expiry", "15m") 37 viper.SetDefault("auth_jwt_refresh_expiry", "1h") 38 39 // Cobra supports Persistent Flags which will work for this command 40 // and all subcommands, e.g.: 41 // serveCmd.PersistentFlags().String("foo", "", "A help for foo") 42 43 // Cobra supports local flags which will only run when this command 44 // is called directly, e.g.: 45 // serveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 46 }