mapstore

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 14 Imported by: 1

README

Mapstore

This is an experimental package that allows you to persist data in a ConfigMap.

todo: write up a guide about the usage and why you should think twice about using this package

Documentation

Overview

Package mapstore facilitates saving key value pairs into a Kubernetes ConfigMap.

package main

import (
    "fmt"
    "log"

    "github.com/unrolled/mapstore"
)

func main() {
    mapStore, err := mapstore.NewKeyValue("my-custom-config-map-name", false)
    if err != nil {
        log.Fatalf("error creating mapstore: %v", err)
    }

    err = mapStore.Set("my-key", []byte("my value lives here"))
    if err != nil {
        log.Fatalf("error setting value: %v", err)
    }

    val, err := mapStore.Get("my-key")
    if err != nil {
        log.Fatalf("error getting value: %v", err)
    }

    fmt.Printf("Value from ConfigMap: %#v\n", val)
}

Index

Constants

View Source
const MaxConfigMapSize = 1024

Variables

View Source
var ErrKeyValueNotFound = fmt.Errorf("key was not found")

ErrKeyValueNotFound is returned when looking up a value that does not exist.

Functions

func VerifyConnection

func VerifyConnection(testMapName string, client *KubeClient) error

Types

type ComplexInterface added in v0.0.3

type ComplexInterface interface {
	SimpleInterface
	Raw() (map[string][]byte, error)
	ForceSet(key string, value []byte) error
}

ComplexInterface defines the required methods and a few optional methods for the KeyValue implementation.

type KeyValue

type KeyValue struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

KeyValue is a thread safe key value store backed by a Kubernetes ConfigMap.

func NewKeyValue

func NewKeyValue(cmName string, cacheInternally bool) (*KeyValue, error)

NewKeyValue returns a newly setup instance of KeyValue.

func (*KeyValue) Delete

func (k *KeyValue) Delete(key string) error

Delete removes the given key from the underlying configmap.

func (*KeyValue) ForceSet

func (k *KeyValue) ForceSet(key string, value []byte) error

ForceSet is the same as Set, but does not check if the values are equal first.

func (*KeyValue) Get

func (k *KeyValue) Get(key string) ([]byte, error)

Get uses the supplied key and attempts to return the coorsponding value from the ConfigMap.

func (*KeyValue) Keys added in v0.0.2

func (k *KeyValue) Keys() ([]string, error)

func (*KeyValue) Raw added in v0.0.3

func (k *KeyValue) Raw() (map[string][]byte, error)

Raw returns the actual underlying map data.

func (*KeyValue) Reset added in v0.0.3

func (k *KeyValue) Reset() error

Reset removes all the data from the underlying configmap.

func (*KeyValue) Set

func (k *KeyValue) Set(key string, value []byte) error

Set checks if the value has changed before performing the underlying save call.

type KubeClient

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

KubeClient wires up the connection to the cluster.

func GetKubeClient

func GetKubeClient() (*KubeClient, error)

GetKubeClient returns the kubernetes client singleton.

func (*KubeClient) Delete

func (k *KubeClient) Delete(name string) error

func (*KubeClient) Get

func (k *KubeClient) Get(name string) (map[string][]byte, error)

func (*KubeClient) Set

func (k *KubeClient) Set(name string, binaryData map[string][]byte) error

type SimpleInterface added in v0.0.3

type SimpleInterface interface {
	Keys() ([]string, error)
	Get(key string) ([]byte, error)
	Set(key string, value []byte) error
	Delete(key string) error
	Reset() error
}

SimpleInterface defines the required methods to satisfy the KeyValue implementation.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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