kvod

package module
v0.0.0-...-3e7317c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

README

KVoD [Key/Value on Disk], a simple, encrypted key/value storage for Go (now using Generics)

Just a sample:

type User struct {
	Name  string
	Email string
}

func main() {
	store := kvod.Init("./db/", "secret")
	userContainer := kvod.CreateContainer[User](db, "users")

	userContainer.Put("1", User{"a username", "user@memorya.org"})

	user, _ := userContainer.Get("1")
	fmt.Println(user)

	userContainer.Delete("1")
}

The idea is to save each value to a file, under the specified path. The value is serialized using gob and encrypted (with AES256 in GCM mode, with PBKDF2 as key derivation function with 10000 iterations).

The key is always a string. The value can be any type gob supports (https://blog.golang.org/gobs-of-data), so structs, strings, slices and more, using Generics.

TESTS
ok  	github.com/rehacktive/kvod/kvod	0.299s	coverage: 82.1% of statements
Success: Tests passed.
BENCHMARKS
goos: linux
goarch: amd64
pkg: github.com/rehacktive/kvod/kvod
BenchmarkGenerateKey-4   	     100	  19887814 ns/op	     532 B/op	       8 allocs/op
BenchmarkEncrypt-4       	 1000000	      1945 ns/op	    1008 B/op	       7 allocs/op
BenchmarkDecrypt-4       	 2000000	      1079 ns/op	     976 B/op	       6 allocs/op
BenchmarkInit-4          	     100	  16506587 ns/op	    3483 B/op	      24 allocs/op
BenchmarkPut-4           	   20000	     84323 ns/op	    4744 B/op	      59 allocs/op
BenchmarkGet-4           	   20000	     70250 ns/op	   18346 B/op	     383 allocs/op
BenchmarkGetKeys-4       	    3000	    430877 ns/op	  121920 B/op	    2040 allocs/op
BenchmarkSerialize-4     	 1000000	      1461 ns/op	     912 B/op	      12 allocs/op
BenchmarkDeserialize-4   	 1000000	      2085 ns/op	    1088 B/op	      18 allocs/op
PASS
coverage: 79.5% of statements
ok  	github.com/rehacktive/kvod/kvod	19.396s
Success: Benchmarks passed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandom

func GenerateRandom(size int) ([]byte, error)

GenerateRandom generates a random of size provided

func InitCrypto

func InitCrypto(password string, salt []byte) *crypto

InitCrypto inizialize the crypto struct using password and salt to generate the main key

Types

type KVod

type KVod struct {
	// contains filtered or unexported fields
}

KVod basic struct

func Init

func Init(path string, password string) *KVod

Init KVod struct0

type KVodContainer

type KVodContainer[T any] struct {
	// contains filtered or unexported fields
}

func CreateContainer

func CreateContainer[T any](kvod *KVod, containerPath string) *KVodContainer[T]

func (*KVodContainer[T]) Delete

func (m *KVodContainer[T]) Delete(key string) error

Delete a value by key

func (*KVodContainer[T]) Get

func (m *KVodContainer[T]) Get(key string) (*T, error)

Get a struct with key

func (*KVodContainer[T]) GetAll

func (m *KVodContainer[T]) GetAll() (map[string]T, error)

GetAll returns a slice of all data available

func (*KVodContainer[T]) GetData

func (m *KVodContainer[T]) GetData() ([]T, error)

GetAll returns a slice of all data available

func (*KVodContainer[T]) GetKeys

func (m *KVodContainer[T]) GetKeys() ([]string, error)

GetKeys returns a slice of all keys available

func (*KVodContainer[T]) Put

func (m *KVodContainer[T]) Put(key string, value T) error

Put a struct using a string as key

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL