YetAnotherToDoList/cmd/server.go

64 lines
2.4 KiB
Go
Raw Permalink Normal View History

2023-08-19 23:47:36 +02:00
/*
YetAnotherToDoList
Copyright © 2023 gilex-dev gilex-dev@proton.me
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
2023-08-19 23:47:36 +02:00
*/
package cmd
import (
2023-09-01 23:42:19 +02:00
"github.com/spf13/cobra"
"github.com/spf13/viper"
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/globals"
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/server"
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: `Starts the http server for the graphql api`,
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 {
globals.Logger.Println("Unable to bind flag:", err)
2023-09-01 23:42:19 +02:00
}
if err := viper.BindPFlag("server.portHTTP", cmd.Flags().Lookup("portHTTP")); err != nil {
globals.Logger.Println("Unable to bind flag:", err)
}
if err := viper.BindPFlag("server.portHTTPS", cmd.Flags().Lookup("portHTTPS")); err != nil {
globals.Logger.Println("Unable to bind flag:", err)
2023-09-01 23:42:19 +02:00
}
globals.Logger.Println("starting http server...")
server.StartServer(viper.GetInt("server.portHTTP"), viper.GetInt("server.portHTTPS"), viper.GetString("server.certFile"), viper.GetString("server.keyFile"))
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")
serverCmd.Flags().BoolP("debug", "d", false, "Enable debugging (unused)")
serverCmd.Flags().IntP("portHTTP", "p", 4242, "The port to listen on for HTTP")
serverCmd.Flags().Int("portHTTPS", 4241, "The port to listen on for HTTPS")
2023-08-19 23:47:36 +02:00
}