Skip to content

Commit

Permalink
add env var for data path
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrake committed Dec 10, 2018
1 parent 6c2e32b commit 1037949
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions cmd/portal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@ func httpServer(port string, db *db.Db) error {
}

func main() {
port := os.Getenv("PORT")
port := os.Getenv("SIOT_PORT")
if port == "" {
port = "8080"
}

db, err := db.NewDb()
dataDir := os.Getenv("SIOT_DATA")
if dataDir == "" {
dataDir = "./"
}

db, err := db.NewDb(dataDir)
if err != nil {
log.Println("Error opening db: ", err)
os.Exit(-1)
Expand Down
7 changes: 5 additions & 2 deletions db/db.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package db

import (
"path"

"github.com/simpleiot/simpleiot/data"
"github.com/timshannon/bolthold"
)
Expand All @@ -13,8 +15,9 @@ type Db struct {
}

// NewDb creates a new Db instance for the app
func NewDb() (*Db, error) {
store, err := bolthold.Open("data.db", 0666, nil)
func NewDb(dataDir string) (*Db, error) {
dbFile := path.Join(dataDir, "data.db")
store, err := bolthold.Open(dbFile, 0666, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1037949

Please sign in to comment.