Generate main.go
This commit is contained in:
parent
9a83ca204b
commit
00fd369771
|
@ -42,6 +42,10 @@ func generateStaticTmpl() {
|
|||
FileIn: "tmpl/backend/lib/salt/generate-salt.tmpl",
|
||||
FileOut: filepath.Join(AppConfig.OutdirBackend, "lib", "salt", "generate-salt.go"),
|
||||
},
|
||||
{
|
||||
FileIn: "tmpl/backend/lib/config.tmpl",
|
||||
FileOut: filepath.Join(AppConfig.OutdirBackend, "lib", "config.go"),
|
||||
},
|
||||
{
|
||||
FileIn: "tmpl/backend/structs/filter-request.tmpl",
|
||||
FileOut: filepath.Join(AppConfig.OutdirBackend, "structs", "filter-request.go"),
|
||||
|
@ -85,12 +89,15 @@ func generateStaticTmpl() {
|
|||
}
|
||||
|
||||
func generateModelBase() {
|
||||
// main
|
||||
if err := PrepareTmplFile("tmpl/backend/main.tmpl", Project, filepath.Join(AppConfig.OutdirBackend, "main.go")); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// db
|
||||
if err := PrepareTmplFile("tmpl/backend/db/model/user.tmpl", Project, filepath.Join(AppConfig.OutdirBackend, "db", "model", "user.go")); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
/*if err := PrepareTmplFile("tmpl/backend/go.tmpl", Project, filepath.Join(AppConfig.OutdirBackend, "go.mod")); err != nil {
|
||||
log.Fatal(err)
|
||||
}*/
|
||||
if err := PrepareTmplFile("tmpl/backend/db/db.tmpl", Project, filepath.Join(AppConfig.OutdirBackend, "db", "db.go")); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -3,4 +3,6 @@ gorm.io/gorm
|
|||
gorm.io/driver/mysql
|
||||
gorm.io/driver/postgres
|
||||
gorm.io/gorm/logger
|
||||
github.com/golang-jwt/jwt
|
||||
github.com/golang-jwt/jwt
|
||||
github.com/alexflint/go-arg
|
||||
github.com/labstack/echo/v4
|
21
lib/tmpl/backend/lib/config.tmpl
Normal file
21
lib/tmpl/backend/lib/config.tmpl
Normal file
|
@ -0,0 +1,21 @@
|
|||
package lib
|
||||
|
||||
var AppConfig struct {
|
||||
Env string
|
||||
MigrateDB bool
|
||||
DBInstance string
|
||||
DbName string
|
||||
DbAddress string
|
||||
DbPort string
|
||||
DbLogin string
|
||||
DbPassword string
|
||||
Port string
|
||||
|
||||
LdapURL string
|
||||
LdapBind string
|
||||
LdapPassword string
|
||||
LdapSearchBase string
|
||||
|
||||
Nominatim string
|
||||
TileServer string
|
||||
}
|
58
lib/tmpl/backend/main.tmpl
Normal file
58
lib/tmpl/backend/main.tmpl
Normal file
|
@ -0,0 +1,58 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"{{ .Name }}/db"
|
||||
"{{ .Name }}/lib"
|
||||
"{{ .Name }}/middlewares"
|
||||
"{{ .Name }}/routes"
|
||||
|
||||
"github.com/go-co-op/gocron"
|
||||
"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
|
||||
|
||||
func main() {
|
||||
arg.MustParse(&args)
|
||||
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
|
||||
go func() {
|
||||
|
||||
e = echo.New()
|
||||
|
||||
middlewares.Init(e)
|
||||
|
||||
routes.Init(e)
|
||||
|
||||
e.Logger.Fatal(e.Start(fmt.Sprintf(":%s", lib.Config.Port)))
|
||||
}()
|
||||
|
||||
<-sigs
|
||||
|
||||
fmt.Println("Shutdown server")
|
||||
|
||||
_, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if err := e.Shutdown(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println("exiting")
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user