You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. "git.kolaente.de/konrad/Library/models"
  4. "git.kolaente.de/konrad/Library/routes"
  5. "context"
  6. "fmt"
  7. "os"
  8. "os/signal"
  9. "time"
  10. )
  11. // UserLogin Object to recive user credentials in JSON format
  12. type UserLogin struct {
  13. Username string `json:"username" form:"username"`
  14. Password string `json:"password" form:"password"`
  15. }
  16. // Version sets the version to be printed to the user. Gets overwritten by "make release" or "make build" with last git commit or tag.
  17. var Version = "1.0"
  18. func main() {
  19. // Init Config
  20. err := models.SetConfig()
  21. if err != nil {
  22. fmt.Println(err)
  23. os.Exit(1)
  24. }
  25. // Set Engine
  26. err = models.SetEngine()
  27. if err != nil {
  28. fmt.Println(err)
  29. os.Exit(1)
  30. }
  31. // Version notification
  32. fmt.Println("Library version", Version)
  33. // Start the webserver
  34. e := routes.NewEcho()
  35. routes.RegisterRoutes(e)
  36. // Start server
  37. go func() {
  38. if err := e.Start(models.Config.Interface); err != nil {
  39. e.Logger.Info("shutting down the server")
  40. }
  41. }()
  42. // Wait for interrupt signal to gracefully shutdown the server with
  43. // a timeout of 10 seconds.
  44. quit := make(chan os.Signal)
  45. signal.Notify(quit, os.Interrupt)
  46. <-quit
  47. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  48. defer cancel()
  49. fmt.Println("Shutting down...")
  50. if err := e.Shutdown(ctx); err != nil {
  51. e.Logger.Fatal(err)
  52. }
  53. }