tkvs

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: Apache-2.0 Imports: 7 Imported by: 2

README

TKVS - Trivial Key Value store in a single Json file

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, thus available even if caller invokes chroot after.

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")

Documentation

Overview

Trivial Key Value Store with Json Backend

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	KeyVal `json:"keyval"`
}

type KeyVal

type KeyVal map[string][]byte

type TKVS

type TKVS struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(path string, misErr error) *TKVS

func (*TKVS) Delete

func (j *TKVS) Delete(_ context.Context, key string) error

func (*TKVS) Get

func (j *TKVS) Get(_ context.Context, key string) ([]byte, error)

func (*TKVS) Keys

func (j *TKVS) Keys() []string

func (*TKVS) Put

func (j *TKVS) Put(_ context.Context, key string, data []byte) error

Jump to

Keyboard shortcuts

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