add database

This commit is contained in:
Florian Hoss 2022-03-30 13:51:51 +02:00
parent 741861bca4
commit 9c6ddf6c60
2 changed files with 9 additions and 4 deletions

View file

@ -1,6 +1,7 @@
package api package api
import ( import (
"app/database"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -12,12 +13,14 @@ func (api *Api) defineRoutes() {
}) })
} }
func (api *Api) serve(address string) { func (api *Api) initialize() {
api.Router = gin.Default() api.Database = database.Database{Location: "sqlite.db"}
api.Router.Run(address) api.Database.Initialize()
} }
func (api *Api) Run() { func (api *Api) Run() {
api.initialize()
api.Router = gin.Default()
api.defineRoutes() api.defineRoutes()
api.serve(":8080") api.Router.Run()
} }

View file

@ -6,6 +6,8 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
// GCC Toolchain for Windows: https://jmeubank.github.io/tdm-gcc/
func migrateInitial(orm *gorm.DB) { func migrateInitial(orm *gorm.DB) {
err := orm.AutoMigrate(&User{}) err := orm.AutoMigrate(&User{})
if err != nil { if err != nil {