60 lines
2.1 KiB
Go
60 lines
2.1 KiB
Go
/*
|
|
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/>.
|
|
*/
|
|
package cmd
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/globals"
|
|
"somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/server"
|
|
)
|
|
|
|
// serverCmd represents the server command
|
|
var serverCmd = &cobra.Command{
|
|
Use: "server",
|
|
Short: "Start the http server",
|
|
Long: `Starts the http server for the graphql api`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
if err := viper.BindPFlag("debug", cmd.Flags().Lookup("debug")); err != nil {
|
|
globals.Logger.Println("Unable to bind flag:", err)
|
|
}
|
|
if err := viper.BindPFlag("port", cmd.Flags().Lookup("port")); err != nil {
|
|
globals.Logger.Println("Unable to bind flag:", err)
|
|
}
|
|
|
|
globals.Logger.Println("starting http server...")
|
|
server.StartServer(viper.GetInt("server.portHTTP"), viper.GetInt("server.portHTTPS"), viper.GetString("server.certFile"), viper.GetString("server.keyFile"))
|
|
},
|
|
}
|
|
|
|
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")
|
|
serverCmd.Flags().IntP("port", "p", 4242, "The port to listen on")
|
|
}
|