key

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

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

A Key represents the unitque identity of an object. Key schema likes file name of a file system,

Key("/tx/0af020217fd26e0b6bf40912bca223b1dd806a21")
Key("/block/0af020217fd26e0b6bf40912bca223b1dd806a21")
Key("/ttl/peer/a9f827938c7de0")

Inspired by https://github.com/ipfs/go-datastore

func NewKey

func NewKey(s string) Key

NewKey constructs a key from string. it will clean the value.

func NewKeyFromBytes

func NewKeyFromBytes(s []byte) Key

NewKeyFromBytes constructs a key from byte slice. it will clean the value.

func NewKeyWithPathList

func NewKeyWithPathList(l []string) Key

NewKeyWithPathList constructs a key out of a path slice.

func NewKeyWithPaths

func NewKeyWithPaths(p ...string) Key

NewKeyWithPaths constructs a key out of a path slice.

func RawKey

func RawKey(s string) Key

RawKey creates a new Key without safety checking the input. Use with care.

func (Key) Base

func (k Key) Base() Key

Base returns the base key of this key like path.Base(filename)

func (Key) BaseName

func (k Key) BaseName() string

BaseName returns the basename of this key like path.Base(filename)

func (Key) Bytes

func (k Key) Bytes() []byte

Bytes returns the string value of Key as a []byte

func (Key) Child

func (k Key) Child(k2 Key) Key

Child returns the `child` Key of this Key.

func (Key) ChildString

func (k Key) ChildString(s string) Key

ChildString returns the `child` Key of this Key -- string helper.

func (*Key) Clean

func (k *Key) Clean()

Clean up a Key, using path.Clean.

func (Key) Equal

func (k Key) Equal(k2 Key) bool

Equal checks equality of two keys

func (Key) IsAncestorOf

func (k Key) IsAncestorOf(other Key) bool

IsAncestorOf returns whether this key is a prefix of `other`

NewKey("/Ancestor").IsAncestorOf("/Ancestor/Child")
true

func (Key) IsDescendantOf

func (k Key) IsDescendantOf(other Key) bool

IsDescendantOf returns whether this key contains another as a prefix.

NewKey("/Ancestor/Child").IsDescendantOf("/Ancestor")
true

func (Key) IsTopLevel

func (k Key) IsTopLevel() bool

IsTopLevel returns whether this key has only one namespace.

func (Key) Less

func (k Key) Less(k2 Key) bool

Less checks whether this key is sorted lower than another.

func (Key) List

func (k Key) List() []string

List returns the `list` representation of this Key.

NewKey("/block/0af020217fd26e0b6bf40912bca223b1dd806a21").List()
["block", "0af020217fd26e0b6bf40912bca223b1dd806a21"]

func (Key) Parent

func (k Key) Parent() Key

Parent returns the `parent` Key of this Key.

func (Key) String

func (k Key) String() string

Strings is the string value of Key

type Slice

type Slice []Key

Slice attaches the methods of sort.Interface to []Key, sorting in increasing order.

func (Slice) Len

func (p Slice) Len() int

func (Slice) Less

func (p Slice) Less(i, j int) bool

func (Slice) Swap

func (p Slice) Swap(i, j int)

Jump to

Keyboard shortcuts

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