diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-07-26 01:08:03 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-07-26 01:08:03 +0200 |
commit | b03cf48eb2074ef41ced9d59712b005a127c17bf (patch) | |
tree | 8932a34952e372dad70f9cd4c6f6742e9f99c4fb | |
parent | 40407573e35ff9b617faf84ac715de3d791282e4 (diff) | |
download | mdir-b03cf48eb2074ef41ced9d59712b005a127c17bf.tar.gz mdir-b03cf48eb2074ef41ced9d59712b005a127c17bf.tar.bz2 mdir-b03cf48eb2074ef41ced9d59712b005a127c17bf.zip |
feat: Add necessary param for packing
Datadir parameter will make easier for later to create the apk.
-rw-r--r-- | build.yml | 5 | ||||
-rw-r--r-- | db/db.go | 8 | ||||
-rw-r--r-- | main.go | 13 |
3 files changed, 21 insertions, 5 deletions
@@ -13,13 +13,14 @@ secrets: environment: deploy: builds@gabrielgio.me target: artifacts.gabrielgio.me/midr/ + version: v0.1.1 tasks: - archive: | cd midr git archive \ - -o midr-v0.1.0.tar.gz \ - --prefix=midr-v0.1.0/ HEAD + -o midr-$version.tar.gz \ + --prefix=midr-$version/ HEAD - deploy: | cd midr @@ -1,6 +1,8 @@ package db import ( + "path" + "gorm.io/driver/sqlite" "gorm.io/gorm" ) @@ -10,8 +12,10 @@ var ( err error ) -func ConnectDb() { - DB, err = gorm.Open(sqlite.Open("main.db"), &gorm.Config{}) +func ConnectDb(folder string) { + dbPath := path.Join(folder, "main.db") + + DB, err = gorm.Open(sqlite.Open(dbPath), &gorm.Config{}) if err != nil { panic("failed to connect to the database.") @@ -2,19 +2,30 @@ package main import ( "embed" + "flag" "fmt" "git.sr.ht/~gabrielgio/midr/db" "git.sr.ht/~gabrielgio/midr/routes" + "github.com/gin-gonic/gin" ) var Version = "development" +var dataDir = flag.String("d", ".", "Folder where midr will store the data") +var production = flag.Bool("p", false, "Set production") //go:embed assets/* templates/* var f embed.FS func main() { + flag.Parse() fmt.Println("Version:\t", Version) - db.ConnectDb() + fmt.Println("Datadir:\t", *dataDir) + + if *production { + gin.SetMode(gin.ReleaseMode) + } + + db.ConnectDb(*dataDir) routes.HandleRequests(f) } |