Move database load into main()
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
e3838621a9
commit
da31b862a2
10
db.go
10
db.go
|
@ -20,17 +20,17 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"go.elara.ws/logger/log"
|
|
||||||
"go.elara.ws/lure/internal/config"
|
"go.elara.ws/lure/internal/config"
|
||||||
"go.elara.ws/lure/internal/db"
|
"go.elara.ws/lure/internal/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
var gdb *sqlx.DB
|
var gdb *sqlx.DB
|
||||||
|
|
||||||
func init() {
|
func loadDB() error {
|
||||||
var err error
|
ldb, err := db.Open(config.DBPath)
|
||||||
gdb, err = db.Open(config.DBPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error opening database").Err(err).Send()
|
return err
|
||||||
}
|
}
|
||||||
|
gdb = ldb
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
7
main.go
7
main.go
|
@ -62,6 +62,11 @@ func main() {
|
||||||
log.Fatal("Running LURE as root is forbidden as it may cause catastrophic damage to your system").Send()
|
log.Fatal("Running LURE as root is forbidden as it may cause catastrophic damage to your system").Send()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := LoadDB()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error loading database").Err(err).Send()
|
||||||
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
|
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -231,7 +236,7 @@ func main() {
|
||||||
EnableBashCompletion: true,
|
EnableBashCompletion: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := app.RunContext(ctx, os.Args)
|
err = app.RunContext(ctx, os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error while running app").Err(err).Send()
|
log.Error("Error while running app").Err(err).Send()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue