Documentation ¶
Index ¶
- Variables
- func DynamicSelectorToGroups(selector string) ([]string, error)
- func ExtractNextSelector(input string) (string, int)
- func FormatNode(node *Node, format string) (*bytes.Buffer, error)
- func FormatNodes(nodes []*Node, format string) (*bytes.Buffer, error)
- type Condition
- type DynamicSelectorParts
- type EqualCondition
- type InvalidIndexErr
- type KeyEqualCondition
- type Node
- func (n *Node) Delete(selector string) error
- func (n *Node) DeleteMultiple(selector string) error
- func (n *Node) InterfaceValue() interface{}
- func (n *Node) Put(selector string, newValue interface{}) error
- func (n *Node) PutMultiple(selector string, newValue interface{}) error
- func (n *Node) Query(selector string) (*Node, error)
- func (n *Node) QueryMultiple(selector string) ([]*Node, error)
- func (n *Node) String() string
- func (n *Node) Write(writer io.Writer, parser string, writeOptions []storage.ReadWriteOption) error
- func (n *Node) WriteToFile(filename, parser string, writeOptions []storage.ReadWriteOption) error
- type Selector
- type SortedComparisonCondition
- type UnexpectedPreviousNilValue
- type UnhandledCheckType
- type UnknownComparisonOperatorErr
- type UnsupportedSelector
- type UnsupportedTypeForSelector
- type ValueNotFound
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDynamicSelectorBracketMismatch = errors.New("dynamic selector bracket mismatch")
ErrDynamicSelectorBracketMismatch is returned when the number of opening brackets doesn't equal that of the closing brackets.
var ErrMissingPreviousNode = errors.New("missing previous node")
ErrMissingPreviousNode is returned when findValue doesn't have access to the previous node.
Functions ¶
func DynamicSelectorToGroups ¶ added in v1.1.0
DynamicSelectorToGroups takes a dynamic selector and splits it into groups.
func ExtractNextSelector ¶ added in v1.4.1
ExtractNextSelector returns the next selector from the given input.
func FormatNode ¶ added in v1.19.0
FormatNode formats a node with the format template and returns the result.
Types ¶
type DynamicSelectorParts ¶ added in v1.14.0
DynamicSelectorParts contains the parts for a dynamic selector.
func FindDynamicSelectorParts ¶ added in v1.14.0
func FindDynamicSelectorParts(selector string) DynamicSelectorParts
FindDynamicSelectorParts extracts the parts from the dynamic selector given.
type EqualCondition ¶
type EqualCondition struct { // Key is the key of the value to check against. Key string // Value is the value we are looking for. Value string // Not is true if this is a not equal check. Not bool }
EqualCondition lets you check for an exact match.
type InvalidIndexErr ¶
type InvalidIndexErr struct {
Index string
}
InvalidIndexErr is returned when a selector targets an index that does not exist.
func (InvalidIndexErr) Error ¶
func (e InvalidIndexErr) Error() string
Error returns the error message.
func (InvalidIndexErr) Is ¶ added in v1.27.2
func (e InvalidIndexErr) Is(err error) bool
Is implements the errors interface, so the errors.Is() function can be used.
type KeyEqualCondition ¶ added in v1.6.0
type KeyEqualCondition struct { // Value is the value we are looking for. Value string // Not is true if this is a not equal check. Not bool }
KeyEqualCondition lets you check for an exact match.
type Node ¶
type Node struct { // Previous is the previous node in the chain. Previous *Node `json:"-"` // Next contains the next node in the chain. // This is used with Query and Put requests. Next *Node `json:"next,omitempty"` // NextMultiple contains the next nodes in the chain. // This is used with QueryMultiple and PutMultiple requests. // When a major version change occurs this will completely replace Next. NextMultiple []*Node `json:"nextMultiple,omitempty"` // OriginalValue is the value returned from the parser. // In most cases this is the same as Value, but is different for thr YAML parser // as it contains information on the original document. OriginalValue interface{} `json:"-"` // Value is the value of the current node. Value reflect.Value `json:"value"` // Selector is the selector for the current node. Selector Selector `json:"selector"` // contains filtered or unexported fields }
Node represents a single node in the chain of nodes for a selector.
func NewFromFile ¶ added in v1.24.0
NewFromFile returns a new root node by parsing file using specified read parser.
func NewFromReader ¶ added in v1.24.0
NewFromReader returns a new root node by parsing from Reader using specified read parser.
func (*Node) Delete ¶ added in v1.19.0
Delete uses the given selector to find and delete the final node from the current node.
func (*Node) DeleteMultiple ¶ added in v1.19.0
DeleteMultiple uses the given selector to query the current node for every match possible and deletes them from the current node.
func (*Node) InterfaceValue ¶ added in v0.0.3
func (n *Node) InterfaceValue() interface{}
InterfaceValue returns the value stored within the node as an interface{}.
func (*Node) Put ¶
Put finds the node using the given selector and updates it's value. It then attempts to propagate the value back up the chain to the root element.
Example ¶
ExampleNode_Put shows how to update data from go code.
package main import ( "encoding/json" "fmt" "github.com/tomwright/dasel" ) func main() { myData := []byte(`{"name": "Tom"}`) var data interface{} if err := json.Unmarshal(myData, &data); err != nil { panic(err) } rootNode := dasel.New(data) if err := rootNode.Put(".name", "Jim"); err != nil { panic(err) } fmt.Println(rootNode.InterfaceValue()) }
Output: map[name:Jim]
func (*Node) PutMultiple ¶ added in v1.4.0
PutMultiple all applicable nodes for the given selector and updates all of their values to the given value. It then attempts to propagate the value back up the chain to the root element.
func (*Node) Query ¶
Query uses the given selector to query the current node and return the result.
Example ¶
ExampleNode_Query shows how to query data from go code.
package main import ( "encoding/json" "fmt" "github.com/tomwright/dasel" ) func main() { myData := []byte(`{"name": "Tom"}`) var data interface{} if err := json.Unmarshal(myData, &data); err != nil { panic(err) } rootNode := dasel.New(data) result, err := rootNode.Query(".name") if err != nil { panic(err) } fmt.Println(result.InterfaceValue()) }
Output: Tom
func (*Node) QueryMultiple ¶ added in v1.4.0
QueryMultiple uses the given selector to query the current node for every match possible and returns all of the end nodes.
func (*Node) String ¶
String returns the value of the node as a string. No formatting is done here, you get the raw value.
func (*Node) Write ¶ added in v1.24.0
Write writes data to Writer using specified write parser and options.
func (*Node) WriteToFile ¶ added in v1.24.0
func (n *Node) WriteToFile(filename, parser string, writeOptions []storage.ReadWriteOption) error
WriteToFile writes data to the given file with the specified options.
type Selector ¶
type Selector struct { // Raw is the full selector. Raw string `json:"raw"` // Current is the selector to be used with the current node. Current string `json:"current"` // Remaining is the remaining parts of the Raw selector. Remaining string `json:"remaining"` // Type is the type of the selector. Type string `json:"type"` // Property is the name of the property this selector targets, if applicable. Property string `json:"property,omitempty"` // Index is the index to use if applicable. Index int `json:"index,omitempty"` // Conditions contains a set of conditions to optionally match a target. Conditions []Condition `json:"conditions,omitempty"` }
Selector represents the selector for a node.
func ParseSelector ¶
ParseSelector parses the given selector string and returns a Selector.
type SortedComparisonCondition ¶ added in v1.14.0
type SortedComparisonCondition struct { // Key is the key of the value to check against. Key string // Value is the value we are looking for. Value string // Equal is true if the values can match. Equal bool // After is true if the input value should be sorted after the Value. After bool }
SortedComparisonCondition lets you check for an exact match.
type UnexpectedPreviousNilValue ¶
type UnexpectedPreviousNilValue struct {
Selector string
}
UnexpectedPreviousNilValue is returned when the previous node contains a nil value.
func (UnexpectedPreviousNilValue) Error ¶
func (e UnexpectedPreviousNilValue) Error() string
Error returns the error message.
func (UnexpectedPreviousNilValue) Is ¶ added in v1.27.2
func (e UnexpectedPreviousNilValue) Is(err error) bool
Is implements the errors interface, so the errors.Is() function can be used.
type UnhandledCheckType ¶ added in v0.0.3
type UnhandledCheckType struct {
Value interface{}
}
UnhandledCheckType is returned when the a check doesn't know how to deal with the given type
func (UnhandledCheckType) Error ¶ added in v0.0.3
func (e UnhandledCheckType) Error() string
Error returns the error message.
func (UnhandledCheckType) Is ¶ added in v1.27.2
func (e UnhandledCheckType) Is(err error) bool
Is implements the errors interface, so the errors.Is() function can be used.
type UnknownComparisonOperatorErr ¶
type UnknownComparisonOperatorErr struct {
Operator string
}
UnknownComparisonOperatorErr is returned when
func (UnknownComparisonOperatorErr) Error ¶
func (e UnknownComparisonOperatorErr) Error() string
Error returns the error message.
func (UnknownComparisonOperatorErr) Is ¶ added in v1.27.2
func (e UnknownComparisonOperatorErr) Is(err error) bool
Is implements the errors interface, so the errors.Is() function can be used.
type UnsupportedSelector ¶
type UnsupportedSelector struct {
Selector string
}
UnsupportedSelector is returned when a specific selector type is used in the wrong context.
func (UnsupportedSelector) Error ¶
func (e UnsupportedSelector) Error() string
Error returns the error message.
func (UnsupportedSelector) Is ¶ added in v1.27.2
func (e UnsupportedSelector) Is(err error) bool
Is implements the errors interface, so the errors.Is() function can be used.
type UnsupportedTypeForSelector ¶
UnsupportedTypeForSelector is returned when a selector attempts to handle a data type it can't handle.
func (UnsupportedTypeForSelector) Error ¶
func (e UnsupportedTypeForSelector) Error() string
Error returns the error message.
func (UnsupportedTypeForSelector) Is ¶ added in v1.27.2
func (e UnsupportedTypeForSelector) Is(err error) bool
Is implements the errors interface, so the errors.Is() function can be used.
type ValueNotFound ¶
ValueNotFound is returned when a selector string cannot be fully resolved.
func (ValueNotFound) Is ¶ added in v1.27.2
func (e ValueNotFound) Is(err error) bool
Is implements the errors interface, so the errors.Is() function can be used.