modulepackage
0.0.0-20240326202031-e41881815277
Repository: https://github.com/taybart/locknut.git
Documentation: pkg.go.dev
# README
BoltDB Locknut
This is a toy project
A boltdb wrapper to encrypt and decrypt the values stored in the boltdb via AES Cryptor, and also provides common db operations such as GetOne, GetByPrefix, GetKeyList, Save, Delete and etc.
Boltdb file is always open in the file system unless the DB.Close() is called, which cause inconvenience if you want to do some file operations to the db file while the program is running. This package provides the parameter: batchMode to control whether to close the db after each db operation, this has performance impact but could be a useful feature.
Usage Example
import (
"github.com/taybart/locknut"
"github.com/taybart/log"
)
type pii struct {
Name string
}
func main() {
key, err := locknut.GetRandKey()
if err != nil {
log.Fatal(err)
}
bl, err := locknut.NewBoltLocknut("test.db", ".", key, false, []string{"pii", "jids"})
if err != nil {
log.Fatal(err)
}
p := pii{Name: "taylor"}
err = bl.Save("pii", "taylor", p)
if err != nil {
log.Fatal(err)
}
keys, err := bl.GetKeyList("pii", "t")
if err != nil {
log.Fatal(err)
}
log.Info(keys)
dec, err := bl.GetOne("pii", "taylor")
if err != nil {
log.Fatal(err)
}
log.Info(string(dec))
}
Performance
There is no pass for performance yet, please PR!
# Packages
No description provided by the author
# Functions
Decrypt without reciever.
Encrypt recieverless encryption.
GetRandKey gets cryptographically secure 32B.
NewBoltLocknut The main function to initialize the the DB manager for all DB related operations name: the db file name, such as mydb.dat, mytest.db path: the db file's path, can be "" or any other director secret: the secret value if you want to encrypt the values; if you don't want to encrypt the data, simply put it as "" batchMode: to control whether to close the db file after each db operation buckets: the buckets in the db file to be initialized if the db file does not existed.
NewCryptor construct new aes object.
# Variables
The key error messages generated in the package.
The key error messages generated in the package.
The key error messages generated in the package.
# Structs
The BoltLocknut struct, all fields are not needed to be accessed by other packages.
Cryptor used for aes ops.