Documentation ¶
Index ¶
- Variables
- func ExtractStrKeyNameAndSubstring(s interface{}) (string, string, error)
- func ExtractStrKeyNameAndValue(s interface{}) (string, map[string]string, error)
- func FindFieldByName(structType reflect.Type, name string) (reflect.StructField, bool)
- func FindValue(v reflect.Value, keys ...string) reflect.Value
- func FindValueWithParent(pv reflect.Value, cv reflect.Value, keys ...string) (reflect.Value, reflect.Value, string, bool)
- func GetNonIfOrPtrValueDeep(v reflect.Value) reflect.Value
- func GetNonInterfaceValueDeep(v reflect.Value) reflect.Value
- func GetValue(v reflect.Value, keys ...interface{}) reflect.Value
- func IsEmptyInterface(x interface{}) bool
- func IsNilOrInvalidValue(v reflect.Value) bool
- func IsStartedWithUpper(s string) bool
- func IsTypeInterface(t reflect.Type) bool
- func IsTypeMap(t reflect.Type) bool
- func IsTypeScalar(t reflect.Type) bool
- func IsTypeStruct(t reflect.Type) bool
- func IsValMap(v reflect.Value) bool
- func IsValScalar(v reflect.Value) bool
- func IsValueInterface(v reflect.Value) bool
- func IsValueNil(value interface{}) bool
- func IsValueNilOrDefault(value interface{}) bool
- func IsValueSlice(v reflect.Value) bool
- func IsYamlMap(tag string) bool
- func IsYamlScalar(tag string) bool
- func IsYamlSeq(tag string) bool
- func MapFind(m interface{}, key interface{}) (reflect.Value, bool)
- func NewSimpleValue(t reflect.Type, value interface{}) reflect.Value
- func NewValue(t reflect.Type, values ...interface{}) reflect.Value
- func SetChildValue(pv reflect.Value, key interface{}, cv reflect.Value) error
- func SetInternalLog(level InternalLogLevel)
- func SetLog(level LogLevel)
- func SetSignalFilter() chan bool
- func SetValue(v reflect.Value, values ...interface{}) reflect.Value
- func SetValueChild(pv reflect.Value, cv reflect.Value, key interface{}) (reflect.Value, error)
- func SetValueDeep(pv reflect.Value, cv reflect.Value, keys []string, key string, tag string, ...) error
- func SliceDelete(slice interface{}, i int) error
- func SliceFind(slice interface{}, key interface{}) (int, bool)
- func SliceInsert(slice interface{}, i int, val interface{}) error
- func StrKeyGen(kv reflect.Value, structName, keyName string) (string, error)
- func StrKeyStructNew(t reflect.Type, val interface{}) (reflect.Value, error)
- func StrKeyValNew(t reflect.Type, key interface{}) (reflect.Value, error)
- func ToSliceKeys(path string) ([]string, error)
- func ToYAML(path string, value string, isDel bool) ([]byte, error)
- func TypeFind(pt reflect.Type, key string) (reflect.Type, bool)
- func TypeGetAll(t reflect.Type) ([]reflect.Type, bool)
- func UnsetValue(v reflect.Value, key interface{}) error
- func UnsetValueDeep(pv reflect.Value, cv reflect.Value, keys []string, key string) error
- func ValChildDirectSet(pv reflect.Value, key interface{}, cv reflect.Value) (reflect.Value, error)
- func ValChildSet(pv reflect.Value, key interface{}, val interface{}, insertType SearchType) (reflect.Value, error)
- func ValChildUnset(v reflect.Value, key interface{}, deleteType SearchType) (reflect.Value, error)
- func ValFind(v reflect.Value, key interface{}, searchtype SearchType) (reflect.Value, bool)
- func ValFindOrInit(v reflect.Value, key interface{}, searchType SearchType) (reflect.Value, bool)
- func ValGetAll(v reflect.Value) ([]reflect.Value, bool)
- func ValMapFind(v reflect.Value, key interface{}) (reflect.Value, bool)
- func ValMapSet(mv reflect.Value, key interface{}, element interface{}) error
- func ValMapUnset(mv reflect.Value, key interface{}) error
- func ValNew(t reflect.Type, val interface{}) (reflect.Value, error)
- func ValScalarNew(t reflect.Type, val interface{}) (reflect.Value, error)
- func ValScalarSet(v reflect.Value, val interface{}) error
- func ValSliceAppend(v reflect.Value, val interface{}) (reflect.Value, error)
- func ValSliceDelete(v reflect.Value, i int) (reflect.Value, error)
- func ValSliceFind(v reflect.Value, val interface{}) (int, bool)
- func ValSliceIndex(v reflect.Value, index interface{}) (reflect.Value, bool)
- func ValSliceInsert(v reflect.Value, i int, val interface{}) (reflect.Value, error)
- func ValSliceNew(t reflect.Type) (reflect.Value, error)
- func ValSliceVal2Element(v reflect.Value, val interface{}) reflect.Value
- func ValStructFieldFind(sv reflect.Value, structuredkey interface{}, searchtype SearchType) (reflect.Value, bool)
- func ValStructFieldSet(sv reflect.Value, structuredkey interface{}, val interface{}, ...) error
- func ValStructFieldUnset(sv reflect.Value, structuredkey interface{}, deleteType SearchType) error
- func ValStructNew(t reflect.Type, initAllfields bool) (reflect.Value, error)
- func ValYdbSet(v reflect.Value, keys []string, key string, tag string, value string) error
- func ValYdbUnset(v reflect.Value, keys []string, key string) error
- type ConvertOption
- type DataUpdate
- type DataUpdateStartEnd
- type DataUpdateSyncResponse
- type Decoder
- type Encoder
- type InternalLogLevel
- type LogLevel
- type SearchType
- type Updater
- type UpdaterStartEnd
- type UpdaterSyncResponse
- type YDB
- func (db *YDB) AddSyncResponse(path string) error
- func (db *YDB) Close()
- func (db *YDB) Connect(addr string, flags ...string) error
- func (db *YDB) Convert(target interface{}, options ...ConvertOption) error
- func (db *YDB) ConvertToYNode(options ...ConvertOption) (*YNode, error)
- func (db *YDB) DelSyncResponse(path string)
- func (db *YDB) Delete(yaml []byte) error
- func (db *YDB) DeleteFrom(path string) error
- func (db *YDB) Disconnect(addr string) error
- func (db *YDB) EnableAtomicUpdate(enable bool)
- func (db *YDB) EnableWarning(enable bool)
- func (db *YDB) EnhansedSyncTo(syncIgnoredTime time.Duration, prefixSearching bool, paths ...string) error
- func (db *YDB) NewDecoder(r io.Reader) *Decoder
- func (db *YDB) NewEncoder(w io.Writer) *Encoder
- func (db *YDB) Parse(yaml []byte) error
- func (db *YDB) Read(yaml []byte) []byte
- func (db *YDB) ReadFrom(path string) string
- func (db *YDB) Receive() error
- func (db *YDB) Serve()
- func (db *YDB) SetTarget(target interface{}, sync bool) error
- func (db *YDB) Sync(yaml []byte) ([]byte, error)
- func (db *YDB) SyncTo(path ...string) error
- func (db *YDB) Timeout(t time.Duration) error
- func (db *YDB) UpdateCreate(path string, value string) error
- func (db *YDB) UpdateDelete(path string) error
- func (db *YDB) UpdateEnd() error
- func (db *YDB) UpdateReplace(path string, value string) error
- func (db *YDB) UpdateStart() error
- func (db *YDB) UpdateSync(path ...string) error
- func (db *YDB) UpdateSyncPath() []string
- func (db *YDB) Write(yaml []byte) error
- func (db *YDB) WriteTo(path string, value string) error
- type YNode
- func (node *YNode) Find(key string) *YNode
- func (node *YNode) GetChildKeys() []string
- func (node *YNode) GetChildren() []*YNode
- func (node *YNode) GetKey() string
- func (node *YNode) GetMap() map[string]interface{}
- func (node *YNode) GetParent() *YNode
- func (node *YNode) GetTag() string
- func (node *YNode) GetValue() string
- func (node *YNode) Lookup(key string) string
- func (node *YNode) Search(keys ...string) *YNode
- func (node *YNode) Size() int
Constants ¶
This section is empty.
Variables ¶
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 ¶
ExtractStrKeyNameAndSubstring - Extract the struct name, field values
func ExtractStrKeyNameAndValue ¶
ExtractStrKeyNameAndValue - Extract the struct name, field values
func FindFieldByName ¶
FindFieldByName finds struct field by the name.
func FindValue ¶
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 ¶
GetNonIfOrPtrValueDeep - Find the non-interface and non-ptr reflect.value
func GetNonInterfaceValueDeep ¶
GetNonInterfaceValueDeep - Find the non-interface reflect.value
func IsEmptyInterface ¶
func IsEmptyInterface(x interface{}) bool
IsEmptyInterface reports whether x is empty interface
func IsNilOrInvalidValue ¶
IsNilOrInvalidValue reports whether v is nil or reflect.Zero.
func IsStartedWithUpper ¶
IsStartedWithUpper - check the case of a string
func IsTypeInterface ¶
IsTypeInterface reports whether v is an interface.
func IsTypeScalar ¶
IsTypeScalar - true if built-in simple variable type
func IsTypeStruct ¶
IsTypeStruct - true if the type is struct
func IsValScalar ¶
IsValScalar - true if built-in simple variable type
func IsValueInterface ¶
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 ¶
IsValueSlice reports whether v is a slice type.
func IsYamlScalar ¶
IsYamlScalar - Return true if the tag is a scalar.
func NewSimpleValue ¶
NewSimpleValue - Creates a reflect.Value of the simple type.
func SetChildValue ¶
SetChildValue - Set a child value to the parent value.
func SetInternalLog ¶
func SetInternalLog(level InternalLogLevel)
SetInternalLog configures the log level of YDB
func SetValueChild ¶
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 ¶
SliceDelete - Delete an element indexed by i.
func SliceInsert ¶
SliceInsert - Insert an element to the index.
func StrKeyGen ¶
StrKeyGen - Generate the Structured key Multiple keyName must be separated by space.
func StrKeyStructNew ¶
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 ¶
StrKeyValNew - Create a new structured key of the t type.
func ToSliceKeys ¶
ToSliceKeys - Get the sliced key list from the path
func TypeGetAll ¶
TypeGetAll - Get All child values from the struct, map or slice value
func UnsetValue ¶
UnsetValue - Unset a value indicated by the key from parents
func UnsetValueDeep ¶
UnsetValueDeep - finds and unsets a value in deep.
func ValChildDirectSet ¶
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 ¶
ValChildUnset - Unset a child value indicated by the key from parents
func ValFindOrInit ¶
ValFindOrInit - finds or initializes a child value if it is not exists.
func ValMapFind ¶
ValMapFind - Search an element by the key.
func ValMapUnset ¶
ValMapUnset - Remove an element from the map
func ValScalarNew ¶
ValScalarNew - Create a new value of the t type.
func ValScalarSet ¶
ValScalarSet - Create a new value to the pointed value, v.
func ValSliceAppend ¶
ValSliceAppend - Insert an element to the index.
func ValSliceDelete ¶
ValSliceDelete - Delete an element indexed by i. If the slice is not settable, return a new slice.
func ValSliceFind ¶
ValSliceFind - Search an element by value.
func ValSliceIndex ¶
ValSliceIndex - Get an element by index.
func ValSliceInsert ¶
ValSliceInsert - Insert an element to the index. If the slice is not settable, return a new slice.
func ValSliceNew ¶
ValSliceNew - Create a slice.
func ValSliceVal2Element ¶
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 ¶
ValStructNew - Create new struct value and fill out all struct field to zero.
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 ¶
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.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes JSON values to an 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 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 ¶
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 OpenWithSync ¶
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 ¶
AddSyncResponse - registers the path where the UpdaterSyncResponse or DataUpdateSyncResponse interface is executed.
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 ¶
DelSyncResponse - unregisters the path where the UpdaterSyncResponse or DataUpdateSyncResponse interface is executed.
func (*YDB) Delete ¶
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 ¶
DeleteFrom - deletes the value at the target path from the YDB instance
func (*YDB) EnableAtomicUpdate ¶
EnableAtomicUpdate - enables or disables atomic DataUpdate interface for the YDB instance.
func (*YDB) EnableWarning ¶
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 ¶
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 ¶
NewEncoder returns a new encoder that writes to w.
func (*YDB) Read ¶
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) 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 ¶
SetTarget - replace the Target structure Warning - If SetTarget() is called without sync, the data inconsistency happens!
func (*YDB) Sync ¶
Sync - request the update of the YDB instance and return the updated data
foo: >> foo: bar: bar: "hello yaml"
func (*YDB) SyncTo ¶
SyncTo - request the update of the YDB instance
foo: >> foo: bar: bar: "hello yaml"
func (*YDB) UpdateCreate ¶
UpdateCreate function of the DataUpdate interface for *YDB
func (*YDB) UpdateDelete ¶
UpdateDelete function of the DataUpdate interface for *YDB
func (*YDB) UpdateReplace ¶
UpdateReplace function of the DataUpdate interface for *YDB
func (*YDB) UpdateStart ¶
UpdateStart function of the DataUpdateStartEnd interface for *YDB
func (*YDB) UpdateSync ¶
UpdateSync requests the update to remote YDB instances in order to refresh the data nodes.
func (*YDB) UpdateSyncPath ¶
UpdateSyncPath requests the update to remote YDB instances in order to refresh the data nodes.
type YNode ¶
YNode YAML Data Block node
func (*YNode) GetChildKeys ¶
GetChildKeys - Get all child keys
func (*YNode) GetChildren ¶
GetChildren - Get all child YNodes