go(refactor): clean up run.go
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-05-17 20:40:24 +02:00
parent 4de0576c26
commit 72723d951d
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
2 changed files with 14 additions and 21 deletions

@ -40,6 +40,13 @@ func (a *App) SetEchoSettings() {
// TODO: have this in the config.
e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(20)))
// TODO: add check for prometheus config setting.
// if true {
// // import "github.com/labstack/echo-contrib/prometheus"
// p := prometheus.NewPrometheus("echo", nil)
// p.Use(e)
// }
e.Use(middleware.Recover())
e.Use(session.Middleware(

28
run.go

@ -120,11 +120,12 @@ func run() error {
case dbtype != "postgres" && dbtype != "sqlite3":
log.Errorf("unsupported DB type specified, bailing...")
return errUnsupportedDBType
}
setting.SetDbConnstring(connstr)
// type can be one of "postgres" or "sqlite3".
setting.SetDbType(dbtype)
default:
setting.SetDbConnstring(connstr)
// type can be one of "postgres" or "sqlite3".
setting.SetDbType(dbtype)
}
log.Infof("connecting to db at '%s'", connstr)
@ -138,8 +139,7 @@ func run() error {
log.Info("making sure that the db is set up")
err = moddb.SetUp(ctx, db)
if err != nil {
if err = moddb.SetUp(ctx, db); err != nil {
return err
}
@ -153,30 +153,16 @@ func run() error {
a := &app.App{}
err = a.Init(setting, slogger, db)
if err != nil {
if err = a.Init(setting, slogger, db); err != nil {
return err
}
a.PrintConfiguration()
a.SetEmbeds(templates, assets)
a.SetupRoutes()
a.SetEchoSettings()
// a.SetConfig(conf)
// // TODO: add check for prometheus config setting.
// if true {
// // import "github.com/labstack/echo-contrib/prometheus"
// p := prometheus.NewPrometheus("echo", nil)
// p.Use(e)
// }
e := a.E()
// channel used to check whether the app had troubles starting up.
started := make(chan error, 1)