package cmd import ( "context" "log" "time" "github.com/Jaculabilis/intake/core" "github.com/Jaculabilis/intake/web" "github.com/spf13/cobra" ) var serveCmd = &cobra.Command{ Use: "serve", Short: "Serve the web interface", Long: `Serve the intake web interface. `, Run: func(cmd *cobra.Command, args []string) { serve(stringArg(cmd, "addr"), stringArg(cmd, "port")) }, } func init() { rootCmd.AddCommand(serveCmd) serveCmd.Flags().StringP("addr", "a", "localhost", "Address to bind to") serveCmd.Flags().StringP("port", "p", "8081", "Port to bind to") } func serve(addr string, port string) { db := openAndMigrateDb() go core.BackgroundFetch(context.Background(), db, time.Minute) err := web.RunServer(db, addr, port) log.Printf("error: server exited with err: %v", err) }