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
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()
}

View file

@ -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 {