Library/main.go

64 lines
1.3 KiB
Go
Raw Permalink Normal View History

2017-10-06 09:25:37 +00:00
package main
import (
2018-03-05 11:53:12 +00:00
"git.kolaente.de/konrad/Library/models"
"git.kolaente.de/konrad/Library/routes"
2017-12-01 11:47:13 +00:00
"context"
"fmt"
2017-12-01 11:46:47 +00:00
"os"
"os/signal"
2017-12-01 11:47:13 +00:00
"time"
)
2017-10-06 09:25:37 +00:00
2017-11-08 16:12:05 +00:00
// UserLogin Object to recive user credentials in JSON format
type UserLogin struct {
Username string `json:"username" form:"username"`
Password string `json:"password" form:"password"`
}
2018-01-09 11:18:44 +00:00
// Version sets the version to be printed to the user. Gets overwritten by "make release" or "make build" with last git commit or tag.
var Version = "1.0"
2018-01-09 10:39:36 +00:00
2017-11-07 15:35:10 +00: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)
}
2018-01-09 10:39:36 +00:00
// Version notification
fmt.Println("Library version", Version)
// Start the webserver
2017-10-06 10:09:58 +00:00
e := routes.NewEcho()
routes.RegisterRoutes(e)
2017-12-01 11:46:47 +00:00
// Start server
go func() {
if err := e.Start(models.Config.Interface); err != nil {
e.Logger.Info("shutting down the server")
}
}()
// 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)
}
2017-10-06 09:25:37 +00:00
}