stdkiwi

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package stdkiwi implements an API with standard values.

These values include all the values in the package github.com/sdslabs/kiwi/values. It implements all the actions as type-safe functions.

Get Started

Create a store, add key and play with it. It's that easy!

store := stdkiwi.NewStore()

if err := store.AddKey("my_string", "str"); err != nil {
  // handle error
}

myString := store.Str("my_string")

if err := myString.Update("Hello, World!"); err != nil {
  // handle error
}

str, err := myString.Get()
if err != nil {
  // handle error
}

fmt.Println(str) // Hello, World!

For documentation visit https://kiwi.sdslabs.co/docs/concepts-stdkiwi.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

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

Hash implements methods for hash value type.

func (*Hash) Get

func (h *Hash) Get(keys ...string) ([]string, error)

Get gets value(s) of the given key(s).

func (*Hash) Guard

func (h *Hash) Guard()

Guard guards the keys with values of str type.

func (*Hash) GuardE

func (h *Hash) GuardE() error

GuardE is same as Guard but does not panic, instead returns the error.

func (*Hash) Has

func (h *Hash) Has(key string) (bool, error)

Has checks if key is present in the hashmap.

func (*Hash) Insert

func (h *Hash) Insert(key, value string) error

Insert inserts the key-value pair in the hashmap.

func (*Hash) Keys

func (h *Hash) Keys() ([]string, error)

Keys gets all the keys of the hashmap.

func (*Hash) Len

func (h *Hash) Len() (int, error)

Len gets the length of the hashmap.

func (*Hash) Map

func (h *Hash) Map() (map[string]string, error)

Map gets a copy of the hashmap.

func (*Hash) Remove

func (h *Hash) Remove(elements ...string) error

Remove removes the key-value pair(s) from the hashmap.

type List

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

List implements methods for list value type.

func (*List) Append

func (l *List) Append(strings ...string) error

Append appends the strings to the end of list.

func (*List) Find

func (l *List) Find(value string) (int, error)

Find finds the index of the "value". Returns -1 if it does not exist.

func (*List) Get

func (l *List) Get(index int) (string, error)

Get gets the string in the list at "index".

func (*List) Guard

func (l *List) Guard()

Guard guards the keys with values of str type.

func (*List) GuardE

func (l *List) GuardE() error

GuardE is same as Guard but does not panic, instead returns the error.

func (*List) Len

func (l *List) Len() (int, error)

Len gets the length of the list.

func (*List) Pop

func (l *List) Pop(n int) error

Pop pops off the last "n" elements from the end of the list.

func (*List) Remove

func (l *List) Remove(index int) error

Remove removes the elem with the given index.

func (*List) RemoveS

func (l *List) RemoveS(value string) error

RemoveS removes the elem with the given value.

func (*List) Set

func (l *List) Set(index int, set string) error

Set sets the string in the list at "index".

func (*List) Slice

func (l *List) Slice(start, end int) ([]string, error)

Slice slices the list from start to end (end excluded).

type Set

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

Set implements methods for set value type.

func (*Set) Get

func (s *Set) Get() ([]string, error)

Get gets all the elements of the set.

func (*Set) Guard

func (s *Set) Guard()

Guard guards the keys with values of str type.

func (*Set) GuardE

func (s *Set) GuardE() error

GuardE is same as Guard but does not panic, instead returns the error.

func (*Set) Has

func (s *Set) Has(element string) (bool, error)

Has checks if element is present in the set.

func (*Set) Insert

func (s *Set) Insert(elements ...string) error

Insert inserts the elements to the set.

func (*Set) Len

func (s *Set) Len() (int, error)

Len gets the length of the set.

func (*Set) Remove

func (s *Set) Remove(elements ...string) error

Remove removes the elements from the set.

type Store

type Store struct{ *kiwi.Store }

Store wraps the kiwi.Store and implements various API methods for standard values.

func NewStore

func NewStore() *Store

NewStore creates a new std store.

func NewStoreFromSchema

func NewStoreFromSchema(schema kiwi.Schema) (*Store, error)

NewStoreFromSchema creates a new std store from schema.

func (*Store) Hash

func (s *Store) Hash(key string) *Hash

Hash returns a "Hashmap" with the key set as "key".

This does not verify if the key and value type pair is correct. If this does not work, "Do" will eventually throw an error. To avoid this use "GuardE" method or "Guard" if schema is pre-defined.

func (*Store) List

func (s *Store) List(key string) *List

List returns a "List" with the key set as "key".

This does not verify if the key and value type pair is correct. If this does not work, "Do" will eventually throw an error. To avoid this use "GuardE" method or "Guard" if schema is pre-defined.

func (*Store) Set

func (s *Store) Set(key string) *Set

Set returns a "Set" with the key set as "key".

This does not verify if the key and value type pair is correct. If this does not work, "Do" will eventually throw an error. To avoid this use "GuardE" method or "Guard" if schema is pre-defined.

func (*Store) Str

func (s *Store) Str(key string) *Str

Str returns an "Str" with the key set as "key".

This does not verify if the key and value type pair is correct. If this does not work, "Do" will eventually throw an error. To avoid this use "GuardE" method or "Guard" if schema is pre-defined.

func (*Store) Zset

func (s *Store) Zset(key string) *Zset

Zset returns a "Zset" with the key set as "key".

This does not verify if the key and value type pair is correct. If this does not work, "Do" will eventually throw an error. To avoid this use "GuardE" method or "Guard" if schema is pre-defined.

type Str

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

Str implements methods for str value type.

func (*Str) Clear

func (s *Str) Clear() error

Clear empties the string corresponding to the key.

func (*Str) Get

func (s *Str) Get() (string, error)

Get gets the string stored corresponding to the key.

func (*Str) Guard

func (s *Str) Guard()

Guard guards the keys with values of str type.

func (*Str) GuardE

func (s *Str) GuardE() error

GuardE is same as Guard but does not panic, instead returns the error.

func (*Str) Len

func (s *Str) Len() (int, error)

Len returns the length of the string.

func (*Str) Update

func (s *Str) Update(update string) error

Update updates the string corresponding to the key.

type Value

type Value interface {
	// Guard should panic if the key does not correspond to the correct type.
	Guard()

	// GuardE is same as guard but does not panic, instead throws an error.
	GuardE() error
}

Value can be used to access the methods for standard value types.

type Zset

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

Zset implements methods for zset value type.

func (*Zset) Get

func (z *Zset) Get(element string) (int, error)

Get gets the score of element from the zset.

func (*Zset) Guard

func (z *Zset) Guard()

Guard guards the keys with values of str type.

func (*Zset) GuardE

func (z *Zset) GuardE() error

GuardE is same as Guard but does not panic, instead returns the error.

func (*Zset) Increment

func (z *Zset) Increment(element string, score int) error

Increment increment the score of element of the zset.

func (*Zset) Insert

func (z *Zset) Insert(elements ...string) error

Insert inserts the elements to the zset.

func (*Zset) Len

func (z *Zset) Len() (int, error)

Len gets the length of the zset.

func (*Zset) PeekMax

func (z *Zset) PeekMax() (string, error)

PeekMax gets the element with highest score from the zset.

func (*Zset) PeekMin

func (z *Zset) PeekMin() (string, error)

PeekMin gets the element with minimum score from the zset.

func (*Zset) Remove

func (z *Zset) Remove(elements ...string) error

Remove removes the elements from the zset.

Jump to

Keyboard shortcuts

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