Categorygithub.com/taybart/locknut
repositorypackage
0.0.0-20240326202031-e41881815277
Repository: https://github.com/taybart/locknut.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# 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!