Skip to content

Commit

Permalink
ensure data directory exists
Browse files Browse the repository at this point in the history
  • Loading branch information
jon4h committed Jul 19, 2021
1 parent 813b123 commit e7383d2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"fmt"
"os"

"gorm.io/driver/sqlite"
"gorm.io/gorm"
Expand All @@ -12,6 +13,15 @@ var (
DB *gorm.DB
)

func init() {
// ensure folder ./data exists and if not create it
if _, err := os.Stat("./data"); os.IsNotExist(err) {
if err := os.Mkdir("./data", 0755); err != nil {
panic(fmt.Sprintf("[database][init] error: %s", err))
}
}
}

type Config struct {
Debug bool `mapstructure:"debug"`
}
Expand Down

0 comments on commit e7383d2

Please sign in to comment.