From 9c6ddf6c6093c5f35a7945812c37f15ca1b80c1f Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Wed, 30 Mar 2022 13:51:51 +0200 Subject: [PATCH] add database --- Lab01/app/api/api.go | 11 +++++++---- Lab01/app/database/database.go | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Lab01/app/api/api.go b/Lab01/app/api/api.go index 9640931..cf6e83c 100644 --- a/Lab01/app/api/api.go +++ b/Lab01/app/api/api.go @@ -1,6 +1,7 @@ package api import ( + "app/database" "github.com/gin-gonic/gin" ) @@ -12,12 +13,14 @@ func (api *Api) defineRoutes() { }) } -func (api *Api) serve(address string) { - api.Router = gin.Default() - api.Router.Run(address) +func (api *Api) initialize() { + api.Database = database.Database{Location: "sqlite.db"} + api.Database.Initialize() } func (api *Api) Run() { + api.initialize() + api.Router = gin.Default() api.defineRoutes() - api.serve(":8080") + api.Router.Run() } diff --git a/Lab01/app/database/database.go b/Lab01/app/database/database.go index 2049e46..3104662 100644 --- a/Lab01/app/database/database.go +++ b/Lab01/app/database/database.go @@ -6,6 +6,8 @@ import ( "gorm.io/gorm" ) +// GCC Toolchain for Windows: https://jmeubank.github.io/tdm-gcc/ + func migrateInitial(orm *gorm.DB) { err := orm.AutoMigrate(&User{}) if err != nil {