YetAnotherToDoList/cmd/server.go

49 lines
1.3 KiB
Go
Raw Normal View History

2023-08-19 23:47:36 +02:00
/*
2023-09-01 23:42:19 +02:00
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
2023-08-19 23:47:36 +02:00
*/
package cmd
import (
"fmt"
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/server"
2023-09-01 23:42:19 +02:00
"github.com/spf13/cobra"
"github.com/spf13/viper"
2023-08-19 23:47:36 +02:00
)
// serverCmd represents the server command
var serverCmd = &cobra.Command{
Use: "server",
2023-09-01 23:42:19 +02:00
Short: "Start the http server",
Long: ``,
2023-08-19 23:47:36 +02:00
Run: func(cmd *cobra.Command, args []string) {
2023-09-01 23:42:19 +02:00
if err := viper.BindPFlag("debug", cmd.Flags().Lookup("debug")); err != nil {
fmt.Println("Unable to bind flag:", err)
}
if err := viper.BindPFlag("port", cmd.Flags().Lookup("port")); err != nil {
fmt.Println("Unable to bind flag:", err)
}
logger.Println("starting http server...")
server.StartServer(logger, viper.GetInt("port"))
2023-08-19 23:47:36 +02:00
},
}
func init() {
rootCmd.AddCommand(serverCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// serverCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// serverCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
2023-09-01 23:42:19 +02:00
serverCmd.Flags().BoolP("debug", "d", false, "Enable debugging")
serverCmd.Flags().IntP("port", "p", 4242, "The port to listen on")
2023-08-19 23:47:36 +02:00
}