uploader/cmd/server.go

51 lines
1.1 KiB
Go
Raw Normal View History

2024-05-03 08:23:58 +02:00
/*
Copyright © 2024 raul
*/
package cmd
import (
"github.com/spf13/cobra"
2024-05-03 08:31:04 +02:00
"log"
2024-05-03 08:23:58 +02:00
)
// serveCmd represents the serve command
var serveCmd = &cobra.Command{
Use: "server",
Short: "Start HTTP server",
Long: `Start HTTP server`,
Run: func(cmd *cobra.Command, args []string) {
2024-05-03 08:31:04 +02:00
if err := setServerParameters(cmd); err != nil {
log.Fatalf("Error happened trying to set parameters: %v\n", err)
}
2024-05-03 08:23:58 +02:00
server()
},
}
func init() {
rootCmd.AddCommand(serveCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
serveCmd.PersistentFlags().String("port", "1302", "Port for server to listen on")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// serveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
2024-05-03 08:31:04 +02:00
func setServerParameters(cmd *cobra.Command) error {
parameterPort, err := cmd.Flags().GetString("port")
if err != nil {
return err
}
if parameterPort != "" {
listenPort = parameterPort
}
return nil
}