Skip to content

Instantly share code, notes, and snippets.

@xyproto
Last active November 6, 2015 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyproto/87d95ea79ad1019d3599 to your computer and use it in GitHub Desktop.
Save xyproto/87d95ea79ad1019d3599 to your computer and use it in GitHub Desktop.
Example for creating a Bolt database with a specific filename, and retrieving the Bolt database struct
package main
import (
"fmt"
"github.com/boltdb/bolt"
"github.com/xyproto/permissionbolt"
)
func main() {
filename := "bolt.db"
perm, err := permissionbolt.NewWithConf(filename)
if err != nil {
fmt.Println("Could not open database: " + filename)
return
}
userstate := perm.UserState()
if puserstate, ok := userstate.(*permissionbolt.UserState); ok {
boltDB := (*bolt.DB)(puserstate.Database())
fmt.Printf("Bolt database: %v\n", boltDB)
} else {
fmt.Println("Not using the Bolt database backend")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment