2018-06-10 11:11:41 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-07-25 16:24:46 +02:00
|
|
|
"code.vikunja.io/api/models"
|
|
|
|
"code.vikunja.io/api/routes"
|
2018-06-10 11:11:41 +02:00
|
|
|
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Version sets the version to be printed to the user. Gets overwritten by "make release" or "make build" with last git commit or tag.
|
2018-07-14 17:34:59 +02:00
|
|
|
var Version = "0.1"
|
2018-06-10 11:11:41 +02:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
// Init Config
|
|
|
|
err := models.SetConfig()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Engine
|
|
|
|
err = models.SetEngine()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version notification
|
2018-07-24 13:56:57 +02:00
|
|
|
fmt.Println("Vikunja version", Version)
|
2018-06-10 11:11:41 +02:00
|
|
|
|
|
|
|
// Start the webserver
|
|
|
|
e := routes.NewEcho()
|
|
|
|
routes.RegisterRoutes(e)
|
|
|
|
// Start server
|
|
|
|
go func() {
|
|
|
|
if err := e.Start(models.Config.Interface); err != nil {
|
2018-06-10 11:34:59 +02:00
|
|
|
e.Logger.Info("shutting down...")
|
2018-06-10 11:11:41 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Wait for interrupt signal to gracefully shutdown the server with
|
|
|
|
// a timeout of 10 seconds.
|
|
|
|
quit := make(chan os.Signal)
|
|
|
|
signal.Notify(quit, os.Interrupt)
|
|
|
|
<-quit
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
fmt.Println("Shutting down...")
|
|
|
|
if err := e.Shutdown(ctx); err != nil {
|
|
|
|
e.Logger.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|