mirror of
https://github.com/Unkn0wnCat/calapi.git
synced 2025-06-18 07:41:37 +02:00
Initial commit
This commit is contained in:
commit
15407746e3
37 changed files with 8525 additions and 0 deletions
39
cmd/serve.go
Normal file
39
cmd/serve.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue