Move some things around a bit

This commit is contained in:
Brian Buller 2016-01-29 13:47:48 -06:00
parent 1c7863fe49
commit 116bfa95d8

View File

@ -2,7 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/boltdb/bolt" "github.com/br0xen/bolt"
"os" "os"
"strings" "strings"
) )
@ -15,17 +15,26 @@ func main() {
} }
filename := args[0] filename := args[0]
var db *bolt.DB
var err error
if len(args) > 1 && args[1] == "build" { if len(args) > 1 && args[1] == "build" {
if _, err := os.Stat(filename); err == nil { if _, stat_err := os.Stat(filename); stat_err == nil {
fmt.Printf("Cowardly refusing to overwrite file: %s\n", filename) fmt.Printf("Cowardly refusing to overwrite file: %s\n", filename)
return return
} }
} }
db, err := bolt.Open(filename, 0600, nil)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
//opts := bolt.Options{0, true}
//db, err := bolt.Open(filename, 0600, &opts)
db, err = bolt.Open(filename, 0600, nil)
if err != nil {
fmt.Printf("Error opening DB: %s\n", err)
return
}
defer db.Close() defer db.Close()
if len(args) > 1 { if len(args) > 1 {
@ -33,6 +42,8 @@ func main() {
createTestDatabase(db) createTestDatabase(db)
} else if args[1] == "json" { } else if args[1] == "json" {
jsonDatabase(db) jsonDatabase(db)
} else if args[1] == "go" {
fmt.Print(db.GoString())
} }
} else { } else {
printDatabase(db) printDatabase(db)