api/main.go

87 lines
2.2 KiB
Go
Raw Normal View History

2018-11-26 20:17:33 +00:00
// Vikunja is a todo-list application to facilitate your life.
// Copyright 2018 Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-06-10 09:11:41 +00:00
package main
import (
"code.vikunja.io/api/docs"
2018-10-31 12:42:38 +00:00
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/mail"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/routes"
2018-06-10 09:11:41 +00:00
"context"
"github.com/spf13/viper"
2018-06-10 09:11:41 +00:00
"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 15:34:59 +00:00
var Version = "0.1"
2018-06-10 09:11:41 +00:00
func main() {
2018-09-19 06:35:53 +00:00
// Init logging
2018-10-31 12:42:38 +00:00
log.InitLogger()
2018-09-19 06:35:53 +00:00
2018-06-10 09:11:41 +00:00
// Init Config
2018-10-31 12:42:38 +00:00
err := config.InitConfig()
2018-06-10 09:11:41 +00:00
if err != nil {
2018-10-31 12:42:38 +00:00
log.Log.Error(err.Error())
2018-06-10 09:11:41 +00:00
os.Exit(1)
}
// Set Engine
err = models.SetEngine()
if err != nil {
2018-10-31 12:42:38 +00:00
log.Log.Error(err.Error())
2018-06-10 09:11:41 +00:00
os.Exit(1)
}
2018-10-27 09:33:28 +00:00
// Start the mail daemon
mail.StartMailDaemon()
2018-06-10 09:11:41 +00:00
// Version notification
2018-10-31 12:42:38 +00:00
log.Log.Infof("Vikunja version %s", Version)
2018-06-10 09:11:41 +00:00
// Additional swagger information
docs.SwaggerInfo.Version = Version
2018-06-10 09:11:41 +00:00
// Start the webserver
e := routes.NewEcho()
routes.RegisterRoutes(e)
// Start server
go func() {
if err := e.Start(viper.GetString("service.interface")); err != nil {
2018-06-10 09:34:59 +00:00
e.Logger.Info("shutting down...")
2018-06-10 09:11:41 +00: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()
2018-10-31 12:42:38 +00:00
log.Log.Infof("Shutting down...")
2018-06-10 09:11:41 +00:00
if err := e.Shutdown(ctx); err != nil {
e.Logger.Fatal(err)
}
}