this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

use env for path

+12 -9
+12 -9
database.go
··· 6 6 "fmt" 7 7 "log/slog" 8 8 "os" 9 + "path" 9 10 10 11 "github.com/bugsnag/bugsnag-go/v2" 11 12 _ "github.com/glebarez/go-sqlite" 12 13 ) 13 14 14 - const ( 15 - dbfile = "./data/database.db" 16 - ) 17 - 18 15 func db() { 19 - err := createDbFile() 16 + mountPath := os.Getenv("RAILWAY_VOLUME_MOUNT_PATH") 17 + if mountPath == "" { 18 + bugsnag.Notify(fmt.Errorf("RAILWAY_VOLUME_MOUNT_PATH env not set")) 19 + return 20 + } 21 + dbFilename := path.Join(mountPath, "database.db") 22 + err := createDbFile(dbFilename) 20 23 if err != nil { 21 24 slog.Error("create db file", "error", err) 22 25 bugsnag.Notify(err) 23 26 return 24 27 } 25 28 26 - sqliteDatabase, _ := sql.Open("sqlite", dbfile) // Open the created SQLite File 29 + sqliteDatabase, _ := sql.Open("sqlite", dbFilename) // Open the created SQLite File 27 30 defer sqliteDatabase.Close() 28 31 29 32 createTable(sqliteDatabase) 30 33 read(sqliteDatabase) 31 34 } 32 35 33 - func createDbFile() error { 34 - if _, err := os.Stat(dbfile); !errors.Is(err, os.ErrNotExist) { 36 + func createDbFile(dbFilename string) error { 37 + if _, err := os.Stat(dbFilename); !errors.Is(err, os.ErrNotExist) { 35 38 return nil 36 39 } 37 40 38 - f, err := os.Create(dbfile) 41 + f, err := os.Create(dbFilename) 39 42 if err != nil { 40 43 return fmt.Errorf("create db file : %w", err) 41 44 }