Skip to content
Permalink
Browse files

add env var for data path

  • Loading branch information...
cbrake committed Dec 10, 2018
1 parent 6c2e32b commit 1037949573dcec53119d023e3cb753b5ebe99a93
Showing with 12 additions and 4 deletions.
  1. +7 −2 cmd/portal/main.go
  2. +5 −2 db/db.go
@@ -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)
@@ -1,6 +1,8 @@
package db

import (
"path"

"github.com/simpleiot/simpleiot/data"
"github.com/timshannon/bolthold"
)
@@ -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
}

0 comments on commit 1037949

Please sign in to comment.
You can’t perform that action at this time.