v0.4.0 Latest Latest

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

Go to latest
Published: Apr 7, 2016 License: MIT, MIT Imports: 3 Imported by: 0



Package keytransform introduces a Datastore Shim that transforms keys before passing them to its child. It can be used to manipulate what keys look like to the user, for example namespacing keys, reversing them, etc.

Use the Wrap function to wrap a datastore with any KeyTransform. A KeyTransform is simply an interface with two functions, a conversion and its inverse. For example:

import (
  ktds ""
  ds ""

func reverseKey(k ds.Key) ds.Key {
  return k.Reverse()

func invertKeys(d ds.Datastore) {
  return ktds.Wrap(d, &ktds.Pair{
    Convert: reverseKey,
    Invert: reverseKey,  // reverse is its own inverse.



This section is empty.


This section is empty.


func Wrap

func Wrap(child ds.Datastore, t KeyTransform) *ktds

Wrap wraps a given datastore with a KeyTransform function. The resulting wrapped datastore will use the transform on all Datastore operations.


type Datastore

type Datastore interface {

Datastore is a keytransform.Datastore

type KeyMapping

type KeyMapping func(ds.Key) ds.Key

KeyMapping is a function that maps one key to annother

type KeyTransform

type KeyTransform interface {
	ConvertKey(ds.Key) ds.Key
	InvertKey(ds.Key) ds.Key

KeyTransform is an object with a pair of functions for (invertibly) transforming keys

type Pair

type Pair struct {
	Convert KeyMapping
	Invert  KeyMapping

func (*Pair) ConvertKey

func (t *Pair) ConvertKey(k ds.Key) ds.Key

func (*Pair) InvertKey

func (t *Pair) InvertKey(k ds.Key) ds.Key

Jump to

Keyboard shortcuts

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