Last active
November 6, 2015 11:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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