uploader/cmd/server.go

42 lines
774 B
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)
2024-05-21 08:52:26 +02:00
serveCmd.PersistentFlags().StringP("port", "p", "1302", "Port for server to listen on")
2024-05-03 08:23:58 +02:00
}
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
}