add db to struct
This commit is contained in:
parent
d2164622c4
commit
b3bc1c4965
6
app.go
6
app.go
@ -5,17 +5,19 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gen2brain/beeep"
|
"github.com/gen2brain/beeep"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// App struct
|
// App struct
|
||||||
type App struct {
|
type App struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewApp creates a new App application struct
|
// NewApp creates a new App application struct
|
||||||
func NewApp() *App {
|
func NewApp(db *gorm.DB) *App {
|
||||||
|
|
||||||
return &App{}
|
return &App{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
// startup is called when the app starts. The context is saved
|
// startup is called when the app starts. The context is saved
|
||||||
|
2
main.go
2
main.go
@ -15,8 +15,8 @@ var assets embed.FS
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Create an instance of the app structure
|
// Create an instance of the app structure
|
||||||
app := NewApp()
|
|
||||||
db := model.InitDB()
|
db := model.InitDB()
|
||||||
|
app := NewApp(db)
|
||||||
things := &things.Service{DB: db}
|
things := &things.Service{DB: db}
|
||||||
|
|
||||||
// Create application with options
|
// Create application with options
|
||||||
|
Loading…
x
Reference in New Issue
Block a user