Documentation ¶
Overview ¶
Package keygen is used for generating in importing tools at Couchabse.
Index ¶
Constants ¶
const ( Backtick = '`' Period = '.' )
These constants are added for readability as the escaping can make it confusing
Variables ¶
var ErrEmptyExpression = errors.New("key generator contains an empty expression")
ErrEmptyExpression is returned if the user provides a key generator which is an empty expression.
Functions ¶
This section is empty.
Types ¶
type ExpressionError ¶
type ExpressionError struct {
// contains filtered or unexported fields
}
ExpressionError is returned if the users expression is invalid in some way, the error will contain an index/reason as to where/why the error occurred.
func (ExpressionError) Error ¶
func (e ExpressionError) Error() string
type FieldPath ¶
type FieldPath []string
FieldPath represents a path to a (possibly) nested field in a JSON document for example, "nested.field" or when the field contains a '.' "another.`not.nested`.field".
func NewFieldPath ¶
NewFieldPath parses a field reference (e.g parent.child) and returns a FieldPath struct which represents the various nested objects in the document.
The syntax rules are as follows: 1. Nested fields are separated using a '.' character 2. '`' characters may be used to represent an exact string 3. You may escape '`' characters by "doubling up" '“' represents a single '`' 4. Keys that contain a '.' character but are not nested should be enclosed in '`'
Examples: 1. 'key' -> ['key'] 2. 'nested.key' -> ['nested', 'key'] 3. '`not.a.nested`.key' -> ['not.a.nested', 'key'] 4. '```.key`' -> ['`.key'] 5. '```.key```' -> ['`.key`']
func (FieldPath) RemoveFrom ¶
RemoveFrom removes the field path from the provided object if it exists. No changes will be made to the document if the field does not exist.
type FieldPathError ¶
type FieldPathError struct {
// contains filtered or unexported fields
}
FieldPathError is returned by 'NewFieldPath' when the provided path is invalid in some way, the error will contain a reason as to why the error occurred.
func (FieldPathError) Error ¶
func (e FieldPathError) Error() string
type KeyGenerator ¶
type KeyGenerator []keyGenerator
KeyGenerator is a list of generators which can be used in succession to generate a document key.
func NewKeyGenerator ¶
func NewKeyGenerator(exp string, fDel, gDel rune) (KeyGenerator, error)
NewKeyGenerator parses a key generator using the provided expression, field and generator delimiters.
The following examples assume the default field/generator delimiters used by 'cbimport' using the document below:
{ "key": "value1", "nested": {"key": "value2"}, "nested": {"with.dot": "value3"}, }
Supported generators:
- MONO_INCR a. '#MONO_INCR#' -> '0', '1' ... b. '#MONO_INCR[100]#' -> '100', '101' ...
- UUID a. '#UUID#' -> '67a7f0a4-99a5-4607-b275-c3b436250ad2', '130fff70-4c66-4788-9194-5271f18cb0e1' ...
- Static Text a. 'example' -> 'example'
- Field a. '%key%' -> 'value1' b. '%nested.key%' -> 'value2' c. '%nested.`with.dot`%' -> 'value3'
These generators are useful on their own, however, the real power comes from being able to combine them into more complex expressions, for example: 1. 'key::#MONO_INCR#' -> 'key::1', 'key::2' ... 3. 'user-#UUID#' -> 'user-e0837e46-0d48-45e3-92e7-28031170d23d', 'user-f9a8f39a-b63a-44fc-8455-c493a6cedf60' ... 3. 'key::#UUID#::#MONO_INCR[50]#%key%' -> key::d9c64d00-9c9a-4191-acf3-d882793eccf5::1::value1 ...
type ResultError ¶
type ResultError struct {
// contains filtered or unexported fields
}
ResultError is returned when generating a key for a given document and the given key is invalid, the error will contain a reason.
func (ResultError) Error ¶
func (e ResultError) Error() string