calapi/cmd/serve.go
2023-02-24 22:17:45 +01:00

39 lines
733 B
Go

package cmd
import (
"github.com/Unkn0wnCat/calapi/internal/database"
"github.com/Unkn0wnCat/calapi/internal/server"
"github.com/spf13/cobra"
"log"
"os"
"os/signal"
"syscall"
)
// serveCmd represents the serve command
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Starts the API server",
//Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
err := database.Initialize()
if err != nil {
return err
}
defer database.Shutdown()
go server.Serve()
<-c // Wait for quit signal
log.Println("goodbye, shutting down...")
return nil
},
}
func init() {
rootCmd.AddCommand(serveCmd)
}