kvstore

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_action_proto protoreflect.FileDescriptor

Functions

func Filter

func Filter(dataset map[string]interface{}, shouldRemain func(k string, v interface{}) bool) map[string]interface{}

func FilterByIncludes

func FilterByIncludes(dataset map[string]interface{}, includes []string) map[string]interface{}

FilterByIncludes 将 dataset 中所有不在 includes 或 includes 子元素中的元素筛选掉 dataset 是一个多层数据集合,通常来源于 Export (不能来源于 ExportFlat,因为该函数没有展开逻辑) includes 是一个 key 列表,key 允许存在层级关系,但不允许访问数组子元素 该函数会修改 dataset 如果 includes 为空或 nil 该函数会返回一个空 map

func FlatForHighLevel

func FlatForHighLevel(key string) []string

FlatForHighLevel 返回所有的上层 key,并保证按长度由小到大排序 例如对于 a.b.c 会返回 [a, a.b, a.b.c]

func ImpossibleError

func ImpossibleError() error

func IsKeyIndexNotValid added in v0.1.4

func IsKeyIndexNotValid(err error) bool

func IsKeyTypeNotMatch added in v0.1.4

func IsKeyTypeNotMatch(err error) bool

func IsNotExist added in v0.1.4

func IsNotExist(err error) bool

func TypeName

func TypeName(v interface{}) string

TypeName for Any or AnyValue 返回值可能为 "null", "int", "float", "string", "bool", "map", "list" 对于非 Any 和 AnyValue 的类型均返回 "unknown"

func TypeNameCompare added in v0.1.17

func TypeNameCompare(previous, current string) int

TypeNameCompare 检查两个类型的包含关系 0 代表相同,-1 代表前者范围更小,1 代表后者返回更小 -2 代表检查不通过(二者无交集)

Types

type Action

type Action struct {

	// Types that are assignable to Action:
	//	*Action_Set
	//	*Action_Delete
	//	*Action_Replace
	Action isAction_Action `protobuf_oneof:"action"`
	// contains filtered or unexported fields
}

func JSONToActions

func JSONToActions(data []byte) ([]*Action, error)

func MapToActions added in v0.2.1

func MapToActions(m map[string]interface{}) ([]*Action, error)

func NewClearAction added in v0.2.2

func NewClearAction() *Action

func NewDeleteAction

func NewDeleteAction(key string) *Action

func NewReplaceAction

func NewReplaceAction(new *Map) *Action

func NewSetAction

func NewSetAction(key string, value *Value) *Action

func (*Action) Descriptor deprecated

func (*Action) Descriptor() ([]byte, []int)

Deprecated: Use Action.ProtoReflect.Descriptor instead.

func (*Action) GetAction

func (x *Action) GetAction() isAction_Action

func (*Action) GetDelete

func (x *Action) GetDelete() *Delete

func (*Action) GetReplace

func (x *Action) GetReplace() *Replace

func (*Action) GetSet

func (x *Action) GetSet() *Set

func (*Action) IsDelete

func (x *Action) IsDelete() bool

func (*Action) IsReplace

func (x *Action) IsReplace() bool

func (*Action) IsSet

func (x *Action) IsSet() bool

func (*Action) ProtoMessage

func (*Action) ProtoMessage()

func (*Action) ProtoReflect

func (x *Action) ProtoReflect() protoreflect.Message

func (*Action) Reset

func (x *Action) Reset()

func (*Action) String

func (x *Action) String() string

func (*Action) ToStarlark added in v0.1.19

func (x *Action) ToStarlark() *ActionStarlark

func (*Action) Unwrap

func (x *Action) Unwrap() interface{}

type ActionStarlark added in v0.1.19

type ActionStarlark struct {
	Action  starlark.Value
	Set     *SetStarlark
	Delete  *DeleteStarlark
	Replace *ReplaceStarlark
}

func (*ActionStarlark) Attr added in v0.1.19

func (x *ActionStarlark) Attr(name string) (starlark.Value, error)

func (*ActionStarlark) AttrNames added in v0.1.19

func (x *ActionStarlark) AttrNames() []string

func (*ActionStarlark) Freeze added in v0.1.19

func (x *ActionStarlark) Freeze()

func (*ActionStarlark) Hash added in v0.1.19

func (x *ActionStarlark) Hash() (uint32, error)

func (*ActionStarlark) String added in v0.1.19

func (x *ActionStarlark) String() string

func (*ActionStarlark) Truth added in v0.1.19

func (x *ActionStarlark) Truth() starlark.Bool

func (*ActionStarlark) Type added in v0.1.19

func (x *ActionStarlark) Type() string

type Action_Delete

type Action_Delete struct {
	Delete *Delete `protobuf:"bytes,2,opt,name=delete,proto3,oneof"`
}

type Action_Replace

type Action_Replace struct {
	Replace *Replace `protobuf:"bytes,3,opt,name=replace,proto3,oneof"`
}

type Action_Set

type Action_Set struct {
	Set *Set `protobuf:"bytes,1,opt,name=set,proto3,oneof"`
}

type Any

type Any interface{}

Any 标识着来源于 Value.Unwrap() 的可能返回值 其类型可能为 nil, int64, float64, string, bool, *Map, *List

func ValueToAny

func ValueToAny(from AnyValue) (Any, error)

ValueToAny convert AnyValue to Any, 转换为一一对应 需要注意的是,AnyValue 为字符串形式的 float64 (NaN, Infinity) 则会出现不一致

type AnyValue

type AnyValue interface{}

AnyValue 标识着来源于 Value.AsInterface() 的可能返回值 其类型可能为 nil, int64, float64, string, bool, map[string]interface{}, []interface{}

func AnyToValue

func AnyToValue(from Any) AnyValue

AnyToValue convert Any to AnyValue, 转换为一一对应 需要注意的是,与 Value 的 AsInterface 不同,这一函数并不会特别处理 float infinity 和 NaN

type Applier

type Applier interface {
	ReplaceInner(new *Map)
	Apply(actions []*Action) error
	ApplyAction(action *Action) error
	MockApply(actions []*Action) (Store, error)

	ApplyByJSON(data []byte) error
}

type Checker added in v0.1.3

type Checker interface {
	CheckExist(key string) error
	CheckType(key string, typeName string) error
}

type Clearer added in v0.2.2

type Clearer interface {
	Clear()
}

type Cloner

type Cloner interface {
	Clone() Store
}

type Delete

type Delete struct {
	Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	// contains filtered or unexported fields
}

删除一个值

func (*Delete) Descriptor deprecated

func (*Delete) Descriptor() ([]byte, []int)

Deprecated: Use Delete.ProtoReflect.Descriptor instead.

func (*Delete) GetKey

func (x *Delete) GetKey() string

func (*Delete) ProtoMessage

func (*Delete) ProtoMessage()

func (*Delete) ProtoReflect

func (x *Delete) ProtoReflect() protoreflect.Message

func (*Delete) Reset

func (x *Delete) Reset()

func (*Delete) String

func (x *Delete) String() string

func (*Delete) ToStarlark added in v0.1.19

func (x *Delete) ToStarlark() *DeleteStarlark

type DeleteStarlark added in v0.1.19

type DeleteStarlark struct {
	Key starlark.String
}

func (*DeleteStarlark) Attr added in v0.1.19

func (x *DeleteStarlark) Attr(name string) (starlark.Value, error)

func (*DeleteStarlark) AttrNames added in v0.1.19

func (x *DeleteStarlark) AttrNames() []string

func (*DeleteStarlark) Freeze added in v0.1.19

func (x *DeleteStarlark) Freeze()

func (*DeleteStarlark) Hash added in v0.1.19

func (x *DeleteStarlark) Hash() (uint32, error)

func (*DeleteStarlark) String added in v0.1.19

func (x *DeleteStarlark) String() string

func (*DeleteStarlark) Truth added in v0.1.19

func (x *DeleteStarlark) Truth() starlark.Bool

func (*DeleteStarlark) Type added in v0.1.19

func (x *DeleteStarlark) Type() string

type Deleter

type Deleter interface {
	Delete(key string) error
}

type Dumper added in v0.1.2

type Dumper interface {
	Dump() ([]byte, error)
}

type ErrKeyIndexNotValid

type ErrKeyIndexNotValid struct {
	Key   string
	On    string
	Index int
	Max   int
}

func (ErrKeyIndexNotValid) Error

func (e ErrKeyIndexNotValid) Error() string

type ErrKeyNotExist

type ErrKeyNotExist struct {
	Key string
	On  string
}

func (ErrKeyNotExist) Error

func (e ErrKeyNotExist) Error() string

type ErrKeyTypeNotMatch

type ErrKeyTypeNotMatch struct {
	Key    string
	On     string
	Expect string
	Got    string
}

func (ErrKeyTypeNotMatch) Error

func (e ErrKeyTypeNotMatch) Error() string

type Exporter

type Exporter interface {
	Export() map[string]interface{}
	ExportFlat() map[string]interface{}

	ExportAndFilter(includes []string) map[string]interface{}
	ExportFlatAndFilter(includes []string) map[string]interface{}
}

type Getter

type Getter interface {
	Get(key string) (AnyValue, error)
	GetInt(key string) (int64, error)
	GetFloat(key string) (float64, error)
	GetBool(key string) (bool, error)
	GetString(key string) (string, error)
	GetMap(key string) (map[string]interface{}, error)
	GetList(key string) ([]interface{}, error)
}

type KeySplitter

type KeySplitter interface {
	FlatForHighLevel(key string) []string
	FlatForLowLevel(key string) []string
}

type List

type List = structpb.List

func NewEmptyList

func NewEmptyList() (*List, error)

func NewList

func NewList(v []interface{}) (*List, error)

type Map

type Map = structpb.Dict

func NewEmptyMap

func NewEmptyMap() *Map

func NewMap

func NewMap(v map[string]interface{}) (*Map, error)

type Provider

type Provider = structpb.Dict

type Replace

type Replace struct {
	New *structpb.Dict `protobuf:"bytes,1,opt,name=new,proto3" json:"new,omitempty"`
	// contains filtered or unexported fields
}

完全替换底层数据

func (*Replace) Descriptor deprecated

func (*Replace) Descriptor() ([]byte, []int)

Deprecated: Use Replace.ProtoReflect.Descriptor instead.

func (*Replace) GetNew

func (x *Replace) GetNew() *structpb.Dict

func (*Replace) ProtoMessage

func (*Replace) ProtoMessage()

func (*Replace) ProtoReflect

func (x *Replace) ProtoReflect() protoreflect.Message

func (*Replace) Reset

func (x *Replace) Reset()

func (*Replace) String

func (x *Replace) String() string

func (*Replace) ToStarlark added in v0.1.19

func (x *Replace) ToStarlark() *ReplaceStarlark

type ReplaceStarlark added in v0.1.19

type ReplaceStarlark struct {
	New *starlark.Dict
}

func (*ReplaceStarlark) Attr added in v0.1.19

func (x *ReplaceStarlark) Attr(name string) (starlark.Value, error)

func (*ReplaceStarlark) AttrNames added in v0.1.19

func (x *ReplaceStarlark) AttrNames() []string

func (*ReplaceStarlark) Freeze added in v0.1.19

func (x *ReplaceStarlark) Freeze()

func (*ReplaceStarlark) Hash added in v0.1.19

func (x *ReplaceStarlark) Hash() (uint32, error)

func (*ReplaceStarlark) String added in v0.1.19

func (x *ReplaceStarlark) String() string

func (*ReplaceStarlark) Truth added in v0.1.19

func (x *ReplaceStarlark) Truth() starlark.Bool

func (*ReplaceStarlark) Type added in v0.1.19

func (x *ReplaceStarlark) Type() string

type Set

type Set struct {
	Key   string          `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value *structpb.Value `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

设置一个值

func (*Set) Descriptor deprecated

func (*Set) Descriptor() ([]byte, []int)

Deprecated: Use Set.ProtoReflect.Descriptor instead.

func (*Set) GetKey

func (x *Set) GetKey() string

func (*Set) GetValue

func (x *Set) GetValue() *structpb.Value

func (*Set) ProtoMessage

func (*Set) ProtoMessage()

func (*Set) ProtoReflect

func (x *Set) ProtoReflect() protoreflect.Message

func (*Set) Reset

func (x *Set) Reset()

func (*Set) String

func (x *Set) String() string

func (*Set) ToStarlark added in v0.1.19

func (x *Set) ToStarlark() *SetStarlark

type SetStarlark added in v0.1.19

type SetStarlark struct {
	Key   starlark.String
	Value starlark.Value
}

func (*SetStarlark) Attr added in v0.1.19

func (x *SetStarlark) Attr(name string) (starlark.Value, error)

func (*SetStarlark) AttrNames added in v0.1.19

func (x *SetStarlark) AttrNames() []string

func (*SetStarlark) Freeze added in v0.1.19

func (x *SetStarlark) Freeze()

func (*SetStarlark) Hash added in v0.1.19

func (x *SetStarlark) Hash() (uint32, error)

func (*SetStarlark) String added in v0.1.19

func (x *SetStarlark) String() string

func (*SetStarlark) Truth added in v0.1.19

func (x *SetStarlark) Truth() starlark.Bool

func (*SetStarlark) Type added in v0.1.19

func (x *SetStarlark) Type() string

type Setter

type Setter interface {
	SetNull(key string) error
	SetInt64(key string, value int64) error
	SetUint64(key string, value uint64) error
	SetFloat64(key string, value float64) error
	SetBool(key string, value bool) error
	SetString(key string, value string) error
	SetTrue(key string) error
	SetFalse(key string) error
	SetList(key string, value []interface{}) error
	SetMap(key string, value map[string]interface{}) error

	SetAnyList(key string, value interface{}) error
	SetStringList(key string, value []string) error
	SetAnyMap(key string, value interface{}) error
}

type Store

func CreateStore

func CreateStore(data map[string]interface{}) (Store, error)

func Load added in v0.1.2

func Load(data []byte) (Store, error)

Load 加载来源于 Dump 的数据

func LoadFromJSON

func LoadFromJSON(data []byte) (Store, error)

func NewStore

func NewStore() Store

type TrieNode

type TrieNode struct {
	ParentKey string
	LastKey   string
	Leaf      bool
	Children  map[string]*TrieNode
}

func (*TrieNode) CheckExist

func (n *TrieNode) CheckExist(key string) bool

func (*TrieNode) EnsureGet

func (n *TrieNode) EnsureGet(key string) *TrieNode

func (*TrieNode) FullKey

func (n *TrieNode) FullKey() string

func (*TrieNode) Get

func (n *TrieNode) Get(key string) *TrieNode

type TrieTree

type TrieTree struct {
	Root TrieNode
}

func NewTrie

func NewTrie(names []string) *TrieTree

func (*TrieTree) AddNew

func (t *TrieTree) AddNew(key string)

func (*TrieTree) CheckExist

func (t *TrieTree) CheckExist(key string) bool

type UnsafeApplier

type UnsafeApplier interface {
	UnsafeLocker
	Applier

	UnsafeApply(actions []*Action) error
	UnsafeApplyAction(action *Action) error

	UnsafeMockApplyAndLock(actions []*Action) (Store, error)
	UnsafeReplaceInnerWithoutLock(new *Map)
}

UnsafeApplier 作用是给予异步操作能力的 其实现目的在于支持先 MockApply 来获得修改后的结果 如果满足一定的条件以后执行 ReplaceInner 进行应用,如果不满足则放弃 然而如果使用 Applier 中的版本,会造成 MockApply 和 ReplaceInner 之间可能会出现修改,导致 ReplaceInner 执行后中间修改丢失 因此使用 UnsafeApplier 的流程为 - UnsafeMockApplyAndLock 获得修改结果,检查 - 如果检查通过,利用 UnsafeReplaceInnerWithoutLock 和 UnsafeLock 应用 - 如果检查失败,利用 UnsafeUnlock 放弃

type UnsafeClearer added in v0.2.2

type UnsafeClearer interface {
	UnsafeClear()
}

type UnsafeDeleter added in v0.1.5

type UnsafeDeleter interface {
	UnsafeDelete(key string) error
}

type UnsafeGetter

type UnsafeGetter interface {
	UnsafeGet(key string) (AnyValue, error)
}

type UnsafeLocker

type UnsafeLocker interface {
	UnsafeLock()
	UnsafeUnlock()
	UnsafeRLock()
	UnsafeRUnlock()
}

type UnsafeSetter added in v0.1.5

type UnsafeSetter interface {
	UnsafeSetValueByValue(key string, newValue *Value) error
}

type UnsafeStore

type UnsafeStore interface {
	Store

	UnsafeGetter
	UnsafeSetter
	UnsafeDeleter
	UnsafeClearer
	UnsafeApplier

	UnsafeUnderlying() *Map
	UnsafeUnderlyingPointer() **Map
}

type Value

type Value = structpb.Value

func AnyValueToValue

func AnyValueToValue(from AnyValue) (*Value, error)

AnyValueToValue convert AnyValue to *Value, 转换为一一对应 相比于 NewValue 而言这一函数更加严格(同时效率也更高)

func NewEmptyMapValue

func NewEmptyMapValue() *Value

func NewIntValue

func NewIntValue(v int64) *Value

func NewValue

func NewValue(v interface{}) (*Value, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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