Add user storage test
This commit is contained in:
parent
0c5b4bb04e
commit
137cf3224d
6 changed files with 105 additions and 33 deletions
|
@ -8,6 +8,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
Path directory
|
||||
|
||||
db *bolt.DB
|
||||
|
||||
bucketUsers = []byte("Users")
|
||||
|
@ -16,9 +18,16 @@ var (
|
|||
bucketMessages = []byte("Messages")
|
||||
)
|
||||
|
||||
func Initialize() {
|
||||
log.Println("Storing data at", Path.Root())
|
||||
func Initialize(dir string) {
|
||||
Path = directory(dir)
|
||||
|
||||
err := os.MkdirAll(Path.Logs(), 0700)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Open() {
|
||||
var err error
|
||||
db, err = bolt.Open(Path.Database(), 0600, nil)
|
||||
if err != nil {
|
||||
|
@ -37,8 +46,3 @@ func Initialize() {
|
|||
func Close() {
|
||||
db.Close()
|
||||
}
|
||||
|
||||
func Clear() {
|
||||
os.RemoveAll(Path.Logs())
|
||||
os.Remove(Path.Database())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue