reg

package
v0.0.0-...-b05aa3b Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package reg provide a key-value data storage.

the storage is actually a JSON tree

keys are strings, can be separate into multiple level, like the path of filesystem. the separator is '/', leading and ending '/' is ignored, continious '/' is treat as single '/', so "/foo//bar/" is same as "foo/bar". keys are case sensitive.

internal values should be valid JSON type, i.e. one of nil, bool, float64, string, []interface{} or map[string]interface{}. but we also provide interfaces for compatible types, plus an universal Marshal method. when putting non-standard values into storage, they are converted to JSON types.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound    = errors.New("Not found")
	ErrWrongType   = errors.New("Wrong type")
	ErrEmpyKey     = errors.New("Key is empty")
	ErrInternal    = errors.New("Internal error")
	ErrEndOfObject = errors.New("End of object: '}'")
	ErrEndOfArray  = errors.New("End of array: ']'")
)

Functions

This section is empty.

Types

type Reg

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

Reg is key-value database.

func Decode

func Decode(data []byte) (*Reg, error)

Decode JSON tree

func DecodeReader

func DecodeReader(r io.Reader) (*Reg, error)

DecodeReader decode JSON tree from reader

func (*Reg) Encode

func (rg *Reg) Encode() ([]byte, error)

Encode to JSON tree

func (*Reg) EncodeIndent

func (rg *Reg) EncodeIndent(prefix, indent string) ([]byte, error)

EncodeIndent like Encode, with indentation

func (*Reg) GetBool

func (rg *Reg) GetBool(key string) (x bool, err error)

GetBool get boolean value

func (*Reg) GetBytes

func (rg *Reg) GetBytes(key string) (x []byte, err error)

GetBytes get []byte value decode from base64

func (*Reg) GetFloat32

func (rg *Reg) GetFloat32(key string) (x float32, err error)

GetFloat32 get float32 value

func (*Reg) GetFloat64

func (rg *Reg) GetFloat64(key string) (x float64, err error)

GetFloat64 get float64 value

func (*Reg) GetInt

func (rg *Reg) GetInt(key string) (x int, err error)

GetInt get int value

func (*Reg) GetInt32

func (rg *Reg) GetInt32(key string) (x int32, err error)

GetInt32 get int32 value

func (*Reg) GetInt64

func (rg *Reg) GetInt64(key string) (x int64, err error)

GetInt64 get int64 value

func (*Reg) GetString

func (rg *Reg) GetString(key string) (x string, err error)

GetString get string value

func (*Reg) GetUint

func (rg *Reg) GetUint(key string) (x uint, err error)

GetUint get int value

func (*Reg) GetUint32

func (rg *Reg) GetUint32(key string) (x uint32, err error)

GetUint32 get int32 value

func (*Reg) GetUint64

func (rg *Reg) GetUint64(key string) (x uint64, err error)

GetUint64 get int64 value

func (*Reg) GetUnmarshal

func (rg *Reg) GetUnmarshal(key string, v interface{}) error

GetUnmarshal use josn.Unmarshal to get data at key

func (*Reg) SetBool

func (rg *Reg) SetBool(key string, x bool) error

SetBool set boolean value

func (*Reg) SetBytes

func (rg *Reg) SetBytes(key string, x []byte) error

SetBytes set []byte value encode into base64

func (*Reg) SetFloat32

func (rg *Reg) SetFloat32(key string, x float32) error

SetFloat32 set float32 value

func (*Reg) SetFloat64

func (rg *Reg) SetFloat64(key string, x float64) error

SetFloat64 set float64 value

func (*Reg) SetInt

func (rg *Reg) SetInt(key string, x int) error

SetInt set int value

func (*Reg) SetInt32

func (rg *Reg) SetInt32(key string, x int32) error

SetInt32 set int32 value

func (*Reg) SetInt64

func (rg *Reg) SetInt64(key string, x int64) error

SetInt64 set int64 value

func (*Reg) SetMarshal

func (rg *Reg) SetMarshal(key string, v interface{}) error

SetMarshal use josn.Marshal to set data to key

func (*Reg) SetString

func (rg *Reg) SetString(key string, x string) error

SetString set string value

func (*Reg) SetUint

func (rg *Reg) SetUint(key string, x uint) error

SetUint set uint value

func (*Reg) SetUint32

func (rg *Reg) SetUint32(key string, x float32) error

SetUint32 set float32 value

func (*Reg) SetUint64

func (rg *Reg) SetUint64(key string, x uint64) error

SetUint64 set uint64 value

Jump to

Keyboard shortcuts

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