yt-gen-app/lib/templ/tmpl/backend/main.tmpl
2023-07-26 16:19:28 +03:00

78 lines
1.3 KiB
Cheetah

package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"{{ .Name }}/db"
"{{ .Name }}/lib"
"{{ .Name }}/middleware"
"{{ .Name }}/route"
"github.com/alexflint/go-arg"
"github.com/labstack/echo/v4"
)
var args struct {
RootPath string `arg:"env:ROOT_PATH"`
RootPathAbs string `arg:"-"`
Upload bool `arg:"env:UPLOAD"`
}
var e *echo.Echo
// @title {{ .Title }}
// @version {{ .Version }}
// @description {{ .Description }}
// @termsOfService {{ .TermsOfServices }}
// @contact.name {{ .ContactName }}
// @contact.url {{ .ContactUrl }}
// @contact.email {{ .ContactEmail }}
// @license.name {{ .LicenseName }}
// @license.url {{ .LicenseUrl }}
// @BasePath {{ .BasePath }}
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
func main() {
arg.MustParse(&lib.AppConfig)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
db.DBConnect()
go func() {
e = echo.New()
middleware.Init(e)
route.Init(e)
e.Logger.Fatal(e.Start(fmt.Sprintf(":%s", lib.AppConfig.Port)))
}()
<-sigs
fmt.Println("Shutdown server")
_, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := e.Shutdown(context.Background()); err != nil {
fmt.Println(err)
}
fmt.Println("exiting")
}