ydb

package
v0.0.0-...-d397277 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: GPL-3.0 Imports: 20 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EnableTagLookup enables the tag lookup (e.g. "path") of struct fields for searching data
	EnableTagLookup bool = true
	// CaseInsensitiveFieldLookup enables the case-insensitive struct field name lookup.
	CaseInsensitiveFieldLookup bool = true
	// TagLookupKey is the tag name of the struct field for searching data
	TagLookupKey string = "path"
	// InitChildenOnSet initalizes all struct fields on Set.
	InitChildenOnSet bool = false
)

Functions

func ExtractStrKeyNameAndSubstring

func ExtractStrKeyNameAndSubstring(s interface{}) (string, string, error)

ExtractStrKeyNameAndSubstring - Extract the struct name, field values

func ExtractStrKeyNameAndValue

func ExtractStrKeyNameAndValue(s interface{}) (string, map[string]string, error)

ExtractStrKeyNameAndValue - Extract the struct name, field values

func FindFieldByName

func FindFieldByName(structType reflect.Type, name string) (reflect.StructField, bool)

FindFieldByName finds struct field by the name.

func FindValue

func FindValue(v reflect.Value, keys ...string) reflect.Value

FindValue - finds a value from the struct, map or slice value using the string keys.

func FindValueWithParent

func FindValueWithParent(pv reflect.Value, cv reflect.Value, keys ...string) (reflect.Value, reflect.Value, string, bool)

FindValueWithParent - finds a value and its parent value from the struct, map or slice value using the string keys.

func GetNonIfOrPtrValueDeep

func GetNonIfOrPtrValueDeep(v reflect.Value) reflect.Value

GetNonIfOrPtrValueDeep - Find the non-interface and non-ptr reflect.value

func GetNonInterfaceValueDeep

func GetNonInterfaceValueDeep(v reflect.Value) reflect.Value

GetNonInterfaceValueDeep - Find the non-interface reflect.value

func GetValue

func GetValue(v reflect.Value, keys ...interface{}) reflect.Value

GetValue - gets a value from the struct, map or slice value using the keys.

func IsEmptyInterface

func IsEmptyInterface(x interface{}) bool

IsEmptyInterface reports whether x is empty interface

func IsNilOrInvalidValue

func IsNilOrInvalidValue(v reflect.Value) bool

IsNilOrInvalidValue reports whether v is nil or reflect.Zero.

func IsStartedWithUpper

func IsStartedWithUpper(s string) bool

IsStartedWithUpper - check the case of a string

func IsTypeInterface

func IsTypeInterface(t reflect.Type) bool

IsTypeInterface reports whether v is an interface.

func IsTypeMap

func IsTypeMap(t reflect.Type) bool

IsTypeMap - true if the type is map

func IsTypeScalar

func IsTypeScalar(t reflect.Type) bool

IsTypeScalar - true if built-in simple variable type

func IsTypeStruct

func IsTypeStruct(t reflect.Type) bool

IsTypeStruct - true if the type is struct

func IsValMap

func IsValMap(v reflect.Value) bool

IsValMap - true if built-in map variable type

func IsValScalar

func IsValScalar(v reflect.Value) bool

IsValScalar - true if built-in simple variable type

func IsValueInterface

func IsValueInterface(v reflect.Value) bool

IsValueInterface reports whether v is an interface type.

func IsValueNil

func IsValueNil(value interface{}) bool

IsValueNil returns true if either value is nil, or has dynamic type {ptr, map, slice} with value nil.

func IsValueNilOrDefault

func IsValueNilOrDefault(value interface{}) bool

IsValueNilOrDefault returns true if either IsValueNil(value) or the default value for the type.

func IsValueSlice

func IsValueSlice(v reflect.Value) bool

IsValueSlice reports whether v is a slice type.

func IsYamlMap

func IsYamlMap(tag string) bool

IsYamlMap - Return true if the tag is map object.

func IsYamlScalar

func IsYamlScalar(tag string) bool

IsYamlScalar - Return true if the tag is a scalar.

func IsYamlSeq

func IsYamlSeq(tag string) bool

IsYamlSeq - Return true if the tag is sequence object.

func MapFind

func MapFind(m interface{}, key interface{}) (reflect.Value, bool)

MapFind - Search an element by key.

func NewSimpleValue

func NewSimpleValue(t reflect.Type, value interface{}) reflect.Value

NewSimpleValue - Creates a reflect.Value of the simple type.

func NewValue

func NewValue(t reflect.Type, values ...interface{}) reflect.Value

NewValue - returns new Value based on t type

func SetChildValue

func SetChildValue(pv reflect.Value, key interface{}, cv reflect.Value) error

SetChildValue - Set a child value to the parent value.

func SetInternalLog

func SetInternalLog(level InternalLogLevel)

SetInternalLog configures the log level of YDB

func SetLog

func SetLog(level LogLevel)

SetLog sets ydbLevel (LogLevel of YDB Go API)

func SetSignalFilter

func SetSignalFilter() chan bool

SetSignalFilter -- Set signals to ignore

func SetValue

func SetValue(v reflect.Value, values ...interface{}) reflect.Value

SetValue - Set a value.

func SetValueChild

func SetValueChild(pv reflect.Value, cv reflect.Value, key interface{}) (reflect.Value, error)

SetValueChild - Set a child value to the parent value.

func SetValueDeep

func SetValueDeep(pv reflect.Value, cv reflect.Value, keys []string, key string, tag string, value string) error

SetValueDeep - finds and sets a value.

func SliceDelete

func SliceDelete(slice interface{}, i int) error

SliceDelete - Delete an element indexed by i.

func SliceFind

func SliceFind(slice interface{}, key interface{}) (int, bool)

SliceFind - Search an element by key.

func SliceInsert

func SliceInsert(slice interface{}, i int, val interface{}) error

SliceInsert - Insert an element to the index.

func StrKeyGen

func StrKeyGen(kv reflect.Value, structName, keyName string) (string, error)

StrKeyGen - Generate the Structured key Multiple keyName must be separated by space.

func StrKeyStructNew

func StrKeyStructNew(t reflect.Type, val interface{}) (reflect.Value, error)

StrKeyStructNew - Create new struct value and fill out all struct field. val - must be a string formed as "StructName[StructField1:VAL1][StructField2:VAL2]"

func StrKeyValNew

func StrKeyValNew(t reflect.Type, key interface{}) (reflect.Value, error)

StrKeyValNew - Create a new structured key of the t type.

func ToSliceKeys

func ToSliceKeys(path string) ([]string, error)

ToSliceKeys - Get the sliced key list from the path

func ToYAML

func ToYAML(path string, value string, isDel bool) ([]byte, error)

ToYAML converts the path and value as YAML bytes and then write them to bytes.Buffer.

func TypeFind

func TypeFind(pt reflect.Type, key string) (reflect.Type, bool)

TypeFind - finds a child type from the struct, map or slice value using the key.

func TypeGetAll

func TypeGetAll(t reflect.Type) ([]reflect.Type, bool)

TypeGetAll - Get All child values from the struct, map or slice value

func UnsetValue

func UnsetValue(v reflect.Value, key interface{}) error

UnsetValue - Unset a value indicated by the key from parents

func UnsetValueDeep

func UnsetValueDeep(pv reflect.Value, cv reflect.Value, keys []string, key string) error

UnsetValueDeep - finds and unsets a value in deep.

func ValChildDirectSet

func ValChildDirectSet(pv reflect.Value, key interface{}, cv reflect.Value) (reflect.Value, error)

ValChildDirectSet - Set a child value to the parent value.

func ValChildSet

func ValChildSet(pv reflect.Value, key interface{}, val interface{}, insertType SearchType) (reflect.Value, error)

ValChildSet - finds and sets a child value.

func ValChildUnset

func ValChildUnset(v reflect.Value, key interface{}, deleteType SearchType) (reflect.Value, error)

ValChildUnset - Unset a child value indicated by the key from parents

func ValFind

func ValFind(v reflect.Value, key interface{}, searchtype SearchType) (reflect.Value, bool)

ValFind - finds a child value from the struct, map or slice value using the key.

func ValFindOrInit

func ValFindOrInit(v reflect.Value, key interface{}, searchType SearchType) (reflect.Value, bool)

ValFindOrInit - finds or initializes a child value if it is not exists.

func ValGetAll

func ValGetAll(v reflect.Value) ([]reflect.Value, bool)

ValGetAll - Get All child values from the struct, map or slice value

func ValMapFind

func ValMapFind(v reflect.Value, key interface{}) (reflect.Value, bool)

ValMapFind - Search an element by the key.

func ValMapSet

func ValMapSet(mv reflect.Value, key interface{}, element interface{}) error

ValMapSet - Set an element to the map.

func ValMapUnset

func ValMapUnset(mv reflect.Value, key interface{}) error

ValMapUnset - Remove an element from the map

func ValNew

func ValNew(t reflect.Type, val interface{}) (reflect.Value, error)

ValNew - Create a new value (struct, map, slice) of the t type.

func ValScalarNew

func ValScalarNew(t reflect.Type, val interface{}) (reflect.Value, error)

ValScalarNew - Create a new value of the t type.

func ValScalarSet

func ValScalarSet(v reflect.Value, val interface{}) error

ValScalarSet - Create a new value to the pointed value, v.

func ValSliceAppend

func ValSliceAppend(v reflect.Value, val interface{}) (reflect.Value, error)

ValSliceAppend - Insert an element to the index.

func ValSliceDelete

func ValSliceDelete(v reflect.Value, i int) (reflect.Value, error)

ValSliceDelete - Delete an element indexed by i. If the slice is not settable, return a new slice.

func ValSliceFind

func ValSliceFind(v reflect.Value, val interface{}) (int, bool)

ValSliceFind - Search an element by value.

func ValSliceIndex

func ValSliceIndex(v reflect.Value, index interface{}) (reflect.Value, bool)

ValSliceIndex - Get an element by index.

func ValSliceInsert

func ValSliceInsert(v reflect.Value, i int, val interface{}) (reflect.Value, error)

ValSliceInsert - Insert an element to the index. If the slice is not settable, return a new slice.

func ValSliceNew

func ValSliceNew(t reflect.Type) (reflect.Value, error)

ValSliceNew - Create a slice.

func ValSliceVal2Element

func ValSliceVal2Element(v reflect.Value, val interface{}) reflect.Value

ValSliceVal2Element - Search an element by value.

func ValStructFieldFind

func ValStructFieldFind(sv reflect.Value, structuredkey interface{}, searchtype SearchType) (reflect.Value, bool)

ValStructFieldFind - Find the target structuredkey value from the struct value in depth.

func ValStructFieldSet

func ValStructFieldSet(sv reflect.Value, structuredkey interface{}, val interface{}, insertType SearchType) error

ValStructFieldSet - Set the field of the struct.

func ValStructFieldUnset

func ValStructFieldUnset(sv reflect.Value, structuredkey interface{}, deleteType SearchType) error

ValStructFieldUnset - Remove the field of the struct.

func ValStructNew

func ValStructNew(t reflect.Type, initAllfields bool) (reflect.Value, error)

ValStructNew - Create new struct value and fill out all struct field to zero.

func ValYdbSet

func ValYdbSet(v reflect.Value, keys []string, key string, tag string, value string) error

ValYdbSet - constructs the non-updater struct

func ValYdbUnset

func ValYdbUnset(v reflect.Value, keys []string, key string) error

ValYdbUnset - constructs the non-updater struct

Types

type ConvertOption

type ConvertOption func(*retrieveOption)

ConvertOption - The option to convert the YDB data to YNodes or user-defined go struct.

func ConvertDepth

func ConvertDepth(d int) ConvertOption

ConvertDepth - The option to set the depth of the converted data

func ConvertPath

func ConvertPath(path string) ConvertOption

ConvertPath - The option to set the start point of the converting

func ConvertPathKey

func ConvertPathKey(k ...string) ConvertOption

ConvertPathKey - The option to set the start point of the converting

type DataUpdate

type DataUpdate interface {
	UpdateCreate(path string, value string) error
	UpdateReplace(path string, value string) error
	UpdateDelete(path string) error
}

DataUpdate interface (= Updater with different arguments) to handle a Go struct

type DataUpdateStartEnd

type DataUpdateStartEnd interface {
	UpdateStart() error
	UpdateEnd() error
}

DataUpdateStartEnd indicates the start and end of the data update. They will be called before or after the DataUpdate (Create, Replace and Delete) execution.

type DataUpdateSyncResponse

type DataUpdateSyncResponse interface {
	// SyncResponse is a callback for target data node synchronization.
	// It must return YAML bytes to be updated.
	SyncResponse(path string) []byte
}

DataUpdateSyncResponse - An interface to update the target data node on which a request (DataUpdateSyncRequester) signaled.

type Decoder

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

A Decoder reads and decodes YAML values from an input stream to an YDB instance.

func (*Decoder) Decode

func (dec *Decoder) Decode() error

Decode reads the YAML value from its input and stores it into an YDB instance.

type Encoder

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

An Encoder writes JSON values to an output stream.

func (*Encoder) Encode

func (enc *Encoder) Encode() error

Encode writes the YAML data of an YDB instance to the output stream.

type InternalLogLevel

type InternalLogLevel uint

InternalLogLevel of YDB API (C Library)

const (
	// InternalLogCritical YDB log level
	InternalLogCritical InternalLogLevel = C.YLOG_CRITICAL
	// InternalLogError YDB log level
	InternalLogError InternalLogLevel = C.YLOG_ERROR
	// InternalLogWarn YDB log level
	InternalLogWarn InternalLogLevel = C.YLOG_WARN
	// InternalLogInfo YDB log level
	InternalLogInfo InternalLogLevel = C.YLOG_INFO
	// InternalLogInout YDB log level
	InternalLogInout InternalLogLevel = C.YLOG_INOUT
	// InternalLogDebug YDB log level
	InternalLogDebug InternalLogLevel = C.YLOG_DEBUG
)

type LogLevel

type LogLevel uint

LogLevel of YDB Go API

const (
	// LogCritical YDB log level
	LogCritical LogLevel = 0
	// LogError YDB log level
	LogError LogLevel = 1
	// LogWarn YDB log level
	LogWarn LogLevel = 2
	// LogInfo YDB log level
	LogInfo LogLevel = 3
)

type SearchType

type SearchType int

SearchType - Search option for slice (list) value

const (
	// NoSearch - Do not search of the content of the slice value.
	NoSearch SearchType = iota
	// GetLastEntry - return the last entry of the slice value.
	GetLastEntry
	// GetFirstEntry - return the first entry of the slice value.
	GetFirstEntry
	// SearchByIndex - return an entry of n th index from the slice value.
	SearchByIndex
	// SearchByContent - search an entry by this content.
	SearchByContent
	// DefaultSearchInsertType - default insert or search
	DefaultSearchInsertType SearchType = NoSearch
)

type Updater

type Updater interface {
	Create(keys []string, key string, tag string, value string) error
	Replace(keys []string, key string, tag string, value string) error
	Delete(keys []string, key string) error
}

Updater - An interface to handle a Go struct defined by user

type UpdaterStartEnd

type UpdaterStartEnd interface {
	UpdaterStart() error
	UpdaterEnd() error
}

UpdaterStartEnd indicates the start and end of the data update. They will be called before or after the Updater (Create, Replace and Delete) execution.

type UpdaterSyncResponse

type UpdaterSyncResponse interface {
	// SyncResponse is a callback for target data node synchronization.
	// It must return YAML bytes to be updated.
	SyncResponse(keys []string, key string) []byte
}

UpdaterSyncResponse - An interface to update the target data node on which a request (DataUpdateSyncRequester) signaled.

type YDB

type YDB struct {
	*sync.RWMutex

	Name string

	Errors []error
	// contains filtered or unexported fields
}

YDB (YAML YNode type) to indicate an YDB instance

func New

func New(name string) *YDB

New creates an YDB instance with the name name: The name of the creating YDB instance

func Open

func Open(name string) (*YDB, func())

Open an YDB instance with the name name: The name of the creating YDB instance

func OpenWithSync

func OpenWithSync(name string, target interface{}) (*YDB, func())

OpenWithSync - Open an YDB instance within sync mode.

  • name: The name of the creating YDB instance
  • target: a go struct or map[string]interface{} synced with the YDB instance.

The user must lock and hold to handle the data block using (*YDB).Lock(), Unlock()

func (*YDB) AddSyncResponse

func (db *YDB) AddSyncResponse(path string) error

AddSyncResponse - registers the path where the UpdaterSyncResponse or DataUpdateSyncResponse interface is executed.

func (*YDB) Close

func (db *YDB) Close()

Close the YDB instance

func (*YDB) Connect

func (db *YDB) Connect(addr string, flags ...string) error

Connect to YDB IPC (Inter Process Communication) channel

func (*YDB) Convert

func (db *YDB) Convert(target interface{}, options ...ConvertOption) error

Convert - Convert the YDB data to the target struct or map[string]interface{}.

func (*YDB) ConvertToYNode

func (db *YDB) ConvertToYNode(options ...ConvertOption) (*YNode, error)

ConvertToYNode - returns data that consists of YNodes.

func (*YDB) DelSyncResponse

func (db *YDB) DelSyncResponse(path string)

DelSyncResponse - unregisters the path where the UpdaterSyncResponse or DataUpdateSyncResponse interface is executed.

func (*YDB) Delete

func (db *YDB) Delete(yaml []byte) error

Delete - delete the target data from the YDB instance. e.g. the following /foo/bar's data is deleted from the YDB instance.

foo:
 bar:

func (*YDB) DeleteFrom

func (db *YDB) DeleteFrom(path string) error

DeleteFrom - deletes the value at the target path from the YDB instance

func (*YDB) Disconnect

func (db *YDB) Disconnect(addr string) error

Disconnect to YDB IPC channel

func (*YDB) EnableAtomicUpdate

func (db *YDB) EnableAtomicUpdate(enable bool)

EnableAtomicUpdate - enables or disables atomic DataUpdate interface for the YDB instance.

func (*YDB) EnableWarning

func (db *YDB) EnableWarning(enable bool)

EnableWarning - enables or disables warning return of the YDB instance.

func (*YDB) EnhansedSyncTo

func (db *YDB) EnhansedSyncTo(syncIgnoredTime time.Duration, prefixSearching bool, paths ...string) error

EnhansedSyncTo - request the update to remote YDB instances to refresh the data nodes.

func (*YDB) NewDecoder

func (db *YDB) NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

The decoder introduces its own buffering and may read data from r beyond the YAML values requested.

func (*YDB) NewEncoder

func (db *YDB) NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*YDB) Parse

func (db *YDB) Parse(yaml []byte) error

Parse - parse YAML bytes to update YDB

func (*YDB) Read

func (db *YDB) Read(yaml []byte) []byte

Read - reads YAML bytes from the YDB instance e.g. returns the YAML with /foo/bar's data

foo:          >>   foo:
 bar:               bar: "hello yaml"

func (*YDB) ReadFrom

func (db *YDB) ReadFrom(path string) string

ReadFrom - reads the value(string) from the target path in the YDB instance

func (*YDB) Receive

func (db *YDB) Receive() error

Receive -- Receive the YAML data from remotes.

func (*YDB) Serve

func (db *YDB) Serve()

Serve -- Run Serve() in the main loop if YDB IPC channel is used. Serve() updates the local YDB instance using the received YAML data from remotes.

func (*YDB) SetTarget

func (db *YDB) SetTarget(target interface{}, sync bool) error

SetTarget - replace the Target structure Warning - If SetTarget() is called without sync, the data inconsistency happens!

func (*YDB) Sync

func (db *YDB) Sync(yaml []byte) ([]byte, error)

Sync - request the update of the YDB instance and return the updated data

foo:          >>   foo:
 bar:               bar: "hello yaml"

func (*YDB) SyncTo

func (db *YDB) SyncTo(path ...string) error

SyncTo - request the update of the YDB instance

foo:          >>   foo:
 bar:               bar: "hello yaml"

func (*YDB) Timeout

func (db *YDB) Timeout(t time.Duration) error

Timeout - Sets the timeout of the YDB instance for sync.

func (*YDB) UpdateCreate

func (db *YDB) UpdateCreate(path string, value string) error

UpdateCreate function of the DataUpdate interface for *YDB

func (*YDB) UpdateDelete

func (db *YDB) UpdateDelete(path string) error

UpdateDelete function of the DataUpdate interface for *YDB

func (*YDB) UpdateEnd

func (db *YDB) UpdateEnd() error

UpdateEnd function of the DataUpdateStartEnd interface for *YDB

func (*YDB) UpdateReplace

func (db *YDB) UpdateReplace(path string, value string) error

UpdateReplace function of the DataUpdate interface for *YDB

func (*YDB) UpdateStart

func (db *YDB) UpdateStart() error

UpdateStart function of the DataUpdateStartEnd interface for *YDB

func (*YDB) UpdateSync

func (db *YDB) UpdateSync(path ...string) error

UpdateSync requests the update to remote YDB instances in order to refresh the data nodes.

func (*YDB) UpdateSyncPath

func (db *YDB) UpdateSyncPath() []string

UpdateSyncPath requests the update to remote YDB instances in order to refresh the data nodes.

func (*YDB) Write

func (db *YDB) Write(yaml []byte) error

Write - writes YAML bytes to the YDB instance

func (*YDB) WriteTo

func (db *YDB) WriteTo(path string, value string) error

WriteTo - writes the value string to the target path in the YDB instance

type YNode

type YNode struct {
	Parent *YNode
	Tag    string
	Key    string
	Value  interface{}
}

YNode YAML Data Block node

func (*YNode) Find

func (node *YNode) Find(key string) *YNode

Find - Find a child from the current YNode

func (*YNode) GetChildKeys

func (node *YNode) GetChildKeys() []string

GetChildKeys - Get all child keys

func (*YNode) GetChildren

func (node *YNode) GetChildren() []*YNode

GetChildren - Get all child YNodes

func (*YNode) GetKey

func (node *YNode) GetKey() string

GetKey - Get the current YNode YAML Key

func (*YNode) GetMap

func (node *YNode) GetMap() map[string]interface{}

GetMap - Get all child YNodes

func (*YNode) GetParent

func (node *YNode) GetParent() *YNode

GetParent - Get the parent YNode

func (*YNode) GetTag

func (node *YNode) GetTag() string

GetTag - Get the current YNode YAML Tag

func (*YNode) GetValue

func (node *YNode) GetValue() string

GetValue - Get the current YNode YAML value

func (*YNode) Lookup

func (node *YNode) Lookup(key string) string

Lookup - Get the value of the key named node.

func (*YNode) Search

func (node *YNode) Search(keys ...string) *YNode

Search - Search a child from the current YNode

func (*YNode) Size

func (node *YNode) Size() int

Size - Get the number of children

Jump to

Keyboard shortcuts

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