Hey @kurt , sorry for the necro.
I’m having a hell of a time accessing my volumes contents.
Given the below, I trust that the volume is being attached.
2021-08-24T17:45:44Z [info] Mounting /dev/vdc at /data
I am taking the volume “borp” and mounting it to “/data”, so far so good.
[mounts]
source = "borp"
destination = "/data"
if _, err := os.Stat("data"); os.IsNotExist(err) {
// path/to/whatever does not exist
println("no data")
}
This prints “no data”, it cannot find the volume. I tried ...Stat("/data")
which seems to work, but i still end with a panic
down the line. In addition, the behaviour is different when i run locally, the path /data
doesnt work, data
does.
Here is a small, but full excerpt of the function trying to access a file in the volume-
func PrepareDatabase() {
if _, err := os.Stat("data"); os.IsNotExist(err) {
// path/to/whatever does not exist
println("no data")
}
// create sqlite db in volume if not exist
os.OpenFile("data/sql.db", os.O_CREATE, 0666)
if error != nil {
log.Println("error creating db file", error)
}
database, error := sql.Open("sqlite3", "data/sql.db")
if error != nil {
log.Println(error)
}
defer database.Close()
createStmt, createErr := database.Prepare("CREATE TABLE IF NOT EXISTS totals ( " +
"name TEXT," +
"count INTEGER," +
"PRIMARY KEY('name')" +
")")
createStmt.Exec()
if createErr != nil {
println(createErr)
}
for key := range fields {
log.Print(key)
statement, _ := database.Prepare("INSERT into totals (name, count) VALUES (?, ?)")
statement.Exec(key, 0)
// ^^^ calling exec here is where the app panics
}
}
I’m a Frontend Eng trying to learn, so there might be an obvious finding here