tenox7 / tkvs

Trivial Key Value Store in a Json File

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TKVS - Trivial Key Value store in a Json file

Originally developed as an implementation of the Cache Interface for Go acme/autocert in chroot environments. However it can be used for anything. The key/value store is realized in a single Json file opened on startup, therefore available even if caller invokes chroot.

Usage with ACME

import (
	"github.com/tenox7/tkvs"
	"golang.org/x/crypto/acme/autocert"
)

acm := autocert.Manager{
		Prompt:     autocert.AcceptTOS,
		HostPolicy: autocert.HostWhitelist("www.mysite.com"),
		Cache:      tkvs.New("/var/cache/acme-store.json", autocert.ErrCacheMiss),
}

syscall.Chroot(dir)

General Usage

import "github.com/tenox7/tkvs"

kvs := tkvs.New("/var/cache/mystore.json", errors.New("key not found"))
kvs.Put(ctx, "myKey", []byte("myValue"))
kvs.Get(ctx, "myKey")
kvs.Delete(ctx, "myKey")

About

Trivial Key Value Store in a Json File

License:Apache License 2.0


Languages

Language:Go 100.0%