yangtree

package module
v0.0.0-...-562f0d6 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2022 License: Apache-2.0 Imports: 21 Imported by: 3

README

GoDoc

yangtree (YANG Tree)

yangtree is a Go utilities that can be used to:

  • Build a runtime data tree and enumerated values for a set of YANG modules.
  • Verify the contents of the data tree against the YANG schema. (e.g. range, pattern, when and must statements of the YANG schema)
  • Render the data tree to multiple output formats. For example, XML, YAML, JSON, JSON_IETF, gNMI message, etc.
  • Provide the retrieval of the config, state data nodes separately.
  • Supports the data node access and control using XPath.

Usage

// Load shema from YANG files.
// Load() will load all YANG files from testdata/sample directory.
rootschema, err := yangtree.Load([]string{"../../testdata/sample"}, nil, nil)
if err != nil {
  log.Fatalln(err)
}

// Create a data node from the root schema
// New() creates new data node from the schema node.
rootdata, err := yangtree.New(rootschema)
if err != nil {
  log.Fatalln(err)
}

// Update data tree using simple XPaths and data.
yangtree.SetValueString(rootdata, "/sample/str-val", nil, "hello yangtree!")
yangtree.SetValueString(rootdata, "/sample/single-key-list[list-key=A]/country-code", nil, "KR")
yangtree.SetValueString(rootdata, "/sample/single-key-list[list-key=A]/decimal-range", nil, "10.1")
yangtree.SetValueString(rootdata, "/sample/single-key-list[list-key=A]/empty", nil)
yangtree.SetValueString(rootdata, "/sample/single-key-list[list-key=A]/uint32-range", nil, "200")
yangtree.SetValueString(rootdata, "/sample/single-key-list[list-key=A]/uint64-node", nil, "0987654321")

yangtree.SetValue(rootdata, "sample/multiple-key-list[integer=1][str=first]", nil,
  map[interface{}]interface{}{"integer": 1, "str": "first"})
yangtree.SetValue(rootdata, "sample/single-key-list", nil,
  []interface{}{
    map[interface{}]interface{}{
      "country-code":  "KR",
      "decimal-range": 1.01,
      "empty-node":    nil,
      "list-key":      "B",
      "uint32-range":  100,
      "uint64-node":   1234567890},
  })

// rootdata.Create("sample")

// Print the data tree using RFC7951 (JSON_IETF)
b, err := yangtree.MarshalJSONIndent(rootdata, "", " ", yangtree.RFC7951Format{})
if err != nil {
  log.Fatal(err)
}
fmt.Println(string(b))

// {
//  "sample:sample": {
//   "multiple-key-list": [
//    {
//     "integer": 1,
//     "str": "first"
//    }
//   ],
//   "single-key-list": [
//    {
//     "country-code": "KR",
//     "list-key": "A",
//     "uint32-range": 200
//    },
//    {
//     "country-code": "KR",
//     "decimal-range": 1.01,
//     "empty-node": [
//      null
//     ],
//     "list-key": "B",
//     "uint32-range": 100,
//     "uint64-node": "1234567890"
//    }
//   ],
//   "str-val": "hello yangtree!"
//  }
// }


// Print the data tree using JSON
b, err = yangtree.MarshalJSONIndent(rootdata, "", " ")
if err != nil {
  log.Fatal(err)
}
fmt.Println(string(b))

// {
//  "sample": {
//   "multiple-key-list": {
//    "first": {
//     "1": {
//      "integer": 1,
//      "str": "first"
//     }
//    }
//   },
//   "single-key-list": {
//    "A": {
//     "country-code": "KR",
//     "list-key": "A",
//     "uint32-range": 200
//    },
//    "B": {
//     "country-code": "KR",
//     "decimal-range": 1.01,
//     "empty-node": null,
//     "list-key": "B",
//     "uint32-range": 100,
//     "uint64-node": 1234567890
//    }
//   },
//   "str-val": "hello yangtree!"
//  }
// }

// Print the data tree using YAML
b, err = yangtree.MarshalYAMLIndent(rootdata, "", " ")
if err != nil {
  log.Fatal(err)
}
fmt.Println(string(b))

// sample:
//  multiple-key-list:
//   first:
//    1:
//     integer: 1
//     str: first
//  single-key-list:
//   A:
//    country-code: KR
//    list-key: A
//    uint32-range: 200
//   B:
//    country-code: KR
//    decimal-range: 1.01
//    empty-node: 
//    list-key: B
//    uint32-range: 100
//    uint64-node: 1234567890
//  str-val: hello yangtree!


// Print the data tree using XML
b, err = yangtree.MarshalXMLIndent(rootdata, "", " ")
if err != nil {
  log.Fatal(err)
}
fmt.Println(string(b))

// <root xmlns="https://github.com/neoul/yangtree">
//  <sample xmlns="urn:network">
//   <multiple-key-list>
//    <integer>1</integer>
//    <str>first</str>
//   </multiple-key-list>
//   <single-key-list>
//    <country-code>KR</country-code>
//    <list-key>A</list-key>
//    <uint32-range>200</uint32-range>
//   </single-key-list>
//   <single-key-list>
//    <country-code>KR</country-code>
//    <decimal-range>1.01</decimal-range>
//    <empty-node></empty-node>
//    <list-key>B</list-key>
//    <uint32-range>100</uint32-range>
//    <uint64-node>1234567890</uint64-node>
//   </single-key-list>
//   <str-val>hello yangtree!</str-val>
//  </sample>
// </root>

Sorting by data node key

  • container: schema_name
  • list: schema_name + [key1=val1]
  • non-key-list: schema_name
  • leaf: schema_name
  • leaf-list: schema_name

XPath syntax

ordered-by

yangtree supports ordered-by statement that is used for the ordering of the list and leaf-list entries.

  • The ordered-by statement can be present in lists and leaf-lists with the following types.
    • system: Sorted by the system
    • user: Sorted by the user
  • This statement is ignored if the list represents state data, RPC output parameters, or notification content.
  • The list and leaf-list are defined to ordered-by system by default.
  • insert attribute (metadata) is used for the data node set operation if the list or leaf-list nodes are defined with ordered-by user.
  • The insert attribute has {first, last, before, after}.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capabilities

func Capabilities(namespace, modulename, revision, feature string)

func Delete

func Delete(root DataNode, path string) error

Delete() deletes the target data node in the path if the value is not specified. If the value is specified, only the value is deleted.

func Diff

func Diff(node1, node2 DataNode) ([]DataNode, []DataNode, []DataNode)

Diff() returns differences between nodes. It returns all created, replaced and deleted nodes in node2 (including itself) against node1.

func DiffUpdated

func DiffUpdated(node1, node2 DataNode, disDupCmp bool) ([]DataNode, []DataNode)

DiffUpdated() returns created or updated nodes. It returns all created, replaced nodes in node2 (including itself) against node1. The deleted nodes can be obtained by the reverse input. if disDupCmp (disable duplicatable node comparison) is set, duplicatable nodes are not compared.

func Equal

func Equal(node1, node2 DataNode) bool

Equal() returns true if node1 and node2 have the same data tree and values.

func Error

func Error(etag ErrorTag, err error) error

func Errorf

func Errorf(etag ErrorTag, eMessage string, arg ...interface{}) error

func FindAllPossiblePath

func FindAllPossiblePath(schema *SchemaNode, spath string) []string

FindAllPossiblePath finds all possible paths. It resolves the gNMI path wildcards.

func FindValue

func FindValue(root DataNode, path string) ([]interface{}, error)

FindValue() finds all data in the path and then returns their values.

func FindValueString

func FindValueString(root DataNode, path string) ([]string, error)

FindValueString() finds all data in the path and then returns their values by string.

func FindYangFiles

func FindYangFiles(files []string) ([]string, error)

func GeneratePath

func GeneratePath(schema *SchemaNode, keyPrint, prefixTagging bool) string

func GetKeyValues

func GetKeyValues(node DataNode) ([]string, []string)

Get key-value pairs of the list data node.

func GetOrNew

func GetOrNew(root DataNode, path string) (node DataNode, created DataNode, err error)

GetOrNew returns the target data node and the ancestor node that was created first along the path from the root.

func IsCreatedWithDefault

func IsCreatedWithDefault(schema *SchemaNode) bool

func IsValid

func IsValid(node DataNode) bool

IsValid() return true if it is a valid data node.

func JSONValueToString

func JSONValueToString(jval interface{}) (string, error)

JSONValueToString() returns a string value from the json scalar value that is unmarshalled by json.Unmarshal()

func MarshalJSON

func MarshalJSON(node DataNode, option ...Option) ([]byte, error)

MarshalJSON returns the JSON bytes of a data node.

func MarshalJSONIndent

func MarshalJSONIndent(node DataNode, prefix, indent string, option ...Option) ([]byte, error)

MarshalJSONIndent is like Marshal but applies an indent and a prefix to format the output.

func MarshalXML

func MarshalXML(node DataNode, option ...Option) ([]byte, error)

MarshalXML returns the XML bytes of a data node.

func MarshalXMLIndent

func MarshalXMLIndent(node DataNode, prefix, indent string, option ...Option) ([]byte, error)

MarshalXMLIndent returns the XML bytes of a data node.

func MarshalYAML

func MarshalYAML(node DataNode, option ...Option) ([]byte, error)

MarshalYAML encodes the data node to a YAML document with a number of options. The options available are [ConfigOnly, StateOnly, RFC7951Format, InternalFormat].

func MarshalYAMLIndent

func MarshalYAMLIndent(node DataNode, prefix, indent string, option ...Option) ([]byte, error)

MarshalYAMLIndent encodes the data node to a YAML document with a number of options. The options available are [ConfigOnly, StateOnly, RFC7951Format, InternalFormat].

func Merge

func Merge(root DataNode, path string, src DataNode) error

Merge() merges the src data node to the target data node in the path. The target data node is updated using the src data node.

func Move

func Move(src, dest DataNode) error

Move() moves the src data node to the dest node. The dest node must have the same schema of the src parent nodes.

func NewErrorf

func NewErrorf(etag ErrorTag, eMessage string, arg ...interface{}) error

func PathMap

func PathMap(node []DataNode) map[string]DataNode

PathMap converts the data node list to a map using the path.

func RemovePredicates

func RemovePredicates(path *string) (string, bool)

func Replace

func Replace(root DataNode, path string, new DataNode) error

Replace() replaces the target data node to the new data node in the path.

func SetValue

func SetValue(root DataNode, path string, opt *EditOption, value ...interface{}) error

SetValue sets a value to the target DataNode in the path. If the target DataNode is a branch node, the value must be map[interface{}]interface{} or map[string]interface{}. If the target data node is a leaf or a leaf-list node, the value should be the value.

func SetValueString

func SetValueString(root DataNode, path string, opt *EditOption, value ...string) error

SetValueString sets a value to the target DataNode in the path. If the target DataNode is a branch node, the value must be json or json_ietf bytes. If the target data node is a leaf or a leaf-list node, the value should be string.

func SplitQName

func SplitQName(qname *string) (string, string)

SplitQName splits the namespace qualified name to prefix and node name.

func TokenizeXPathExpr

func TokenizeXPathExpr(token []string, s *string, pos int) ([]string, int, error)

func Traverse

func Traverse(node DataNode, traverser func(DataNode, TrvsCallOption) error, calledAt TrvsCallOption, depth int, leafOnly bool) error

Traverse() loops the node's all children, descendants and itself to execute traverser() at each node.

func UnmarshalJSON

func UnmarshalJSON(node DataNode, jbytes []byte, option ...Option) error

UnmarshalJSON parses the JSON-encoded data and stores the result in the data node.

func UnmarshalXML

func UnmarshalXML(node DataNode, data []byte, option ...Option) error

UnmarshalXML updates the data node using an XML document.

func UnmarshalYAML

func UnmarshalYAML(node DataNode, in []byte, option ...Option) error

UnmarshalYAML updates the data node using YAML-encoded data.

func Unzip

func Unzip(gzj []byte) ([]byte, error)

Unzip() is used to extracts the builtin schema.

func Validate

func Validate(node DataNode) []error

func ValueStringToValue

func ValueStringToValue(schema *SchemaNode, typ *yang.YangType, value string) (interface{}, error)

ValueStringToValue() converts a string value to an yangtree value It also check the range, length and pattern of the schema.

func ValueToValidTypeValue

func ValueToValidTypeValue(schema *SchemaNode, typ *yang.YangType, value interface{}) (interface{}, error)

ValueToValidTypeValue() check the range, length and pattern of the schema.

func ValueToValueString

func ValueToValueString(value interface{}) string

ValueToValueString() converts a golang value to the string value.

Types

type ConfigOnly

type ConfigOnly struct{}

ConfigOnly option is used to find config data nodes that have "config true" statement.

func (ConfigOnly) IsOption

func (f ConfigOnly) IsOption()

func (ConfigOnly) String

func (f ConfigOnly) String() string

type DataBranch

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

The node structure of yangtree for container and list data nodes.

func (*DataBranch) Child

func (branch *DataBranch) Child(index int) DataNode

func (*DataBranch) Children

func (branch *DataBranch) Children() []DataNode

func (*DataBranch) Create

func (branch *DataBranch) Create(id string, value ...string) (DataNode, error)

func (*DataBranch) CreateByMap

func (branch *DataBranch) CreateByMap(pmap map[string]interface{}) error

CreateByMap() updates the data node using pmap (path predicate map) and string values.

func (*DataBranch) Delete

func (branch *DataBranch) Delete(child DataNode) error

func (*DataBranch) Exist

func (branch *DataBranch) Exist(id string) bool

func (*DataBranch) Get

func (branch *DataBranch) Get(id string) DataNode

func (*DataBranch) GetAll

func (branch *DataBranch) GetAll(id string) []DataNode

func (*DataBranch) GetOrNew

func (branch *DataBranch) GetOrNew(id string, insert InsertOption) (DataNode, bool, error)

GetOrNew() gets or creates a node having the id and returns the found or created node with the boolean value that indicates the returned node is created.

func (*DataBranch) GetValue

func (branch *DataBranch) GetValue(id string) interface{}

func (*DataBranch) GetValueString

func (branch *DataBranch) GetValueString(id string) string

func (*DataBranch) HasMultipleValues

func (branch *DataBranch) HasMultipleValues() bool

func (*DataBranch) HasStateNode

func (branch *DataBranch) HasStateNode() bool

func (*DataBranch) HasValueString

func (branch *DataBranch) HasValueString(value string) bool

func (*DataBranch) ID

func (branch *DataBranch) ID() string

func (*DataBranch) Index

func (branch *DataBranch) Index(id string) int

func (*DataBranch) Insert

func (branch *DataBranch) Insert(child DataNode, insert InsertOption) (DataNode, error)

func (*DataBranch) IsBranchNode

func (branch *DataBranch) IsBranchNode() bool

func (*DataBranch) IsContainer

func (branch *DataBranch) IsContainer() bool

func (*DataBranch) IsDataNode

func (branch *DataBranch) IsDataNode()

func (*DataBranch) IsDuplicatableNode

func (branch *DataBranch) IsDuplicatableNode() bool

func (*DataBranch) IsLeaf

func (branch *DataBranch) IsLeaf() bool

func (*DataBranch) IsLeafList

func (branch *DataBranch) IsLeafList() bool

func (*DataBranch) IsLeafNode

func (branch *DataBranch) IsLeafNode() bool

func (*DataBranch) IsList

func (branch *DataBranch) IsList() bool

func (*DataBranch) IsListableNode

func (branch *DataBranch) IsListableNode() bool

func (*DataBranch) IsNil

func (branch *DataBranch) IsNil() bool

func (*DataBranch) IsStateNode

func (branch *DataBranch) IsStateNode() bool

func (*DataBranch) Len

func (branch *DataBranch) Len() int

func (*DataBranch) Lookup

func (branch *DataBranch) Lookup(prefix string) []DataNode

func (*DataBranch) MarshalJSON

func (branch *DataBranch) MarshalJSON() ([]byte, error)

func (*DataBranch) MarshalXML

func (branch *DataBranch) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*DataBranch) MarshalYAML

func (branch *DataBranch) MarshalYAML() (interface{}, error)

func (*DataBranch) Merge

func (branch *DataBranch) Merge(src DataNode) error

Merge() merges the src data node to the branch data node.

func (*DataBranch) Metadata

func (branch *DataBranch) Metadata() map[string]DataNode

func (*DataBranch) Name

func (branch *DataBranch) Name() string

func (*DataBranch) Parent

func (branch *DataBranch) Parent() DataNode

func (*DataBranch) Path

func (branch *DataBranch) Path() string

func (*DataBranch) PathTo

func (branch *DataBranch) PathTo(descendant DataNode) string

func (*DataBranch) QName

func (branch *DataBranch) QName(rfc7951 bool) (string, bool)

func (*DataBranch) Remove

func (branch *DataBranch) Remove() error

func (*DataBranch) Replace

func (branch *DataBranch) Replace(src DataNode) error

Replace() replaces itself to the src node.

func (*DataBranch) Schema

func (branch *DataBranch) Schema() *SchemaNode

func (*DataBranch) SetMetadata

func (branch *DataBranch) SetMetadata(name string, value ...interface{}) error

SetMetadata() sets a metadata. for example, the following last-modified is set to the node as a metadata.

node.SetMetadata("last-modified", "2015-06-18T17:01:14+02:00")

func (*DataBranch) SetMetadataString

func (branch *DataBranch) SetMetadataString(name string, value ...string) error

SetMetadataString() sets a metadata. for example, the following last-modified is set to the node as a metadata.

node.SetMetadataString("last-modified", "2015-06-18T17:01:14+02:00")

func (*DataBranch) SetValue

func (branch *DataBranch) SetValue(value ...interface{}) error

func (*DataBranch) SetValueSafe

func (branch *DataBranch) SetValueSafe(value ...interface{}) error

func (*DataBranch) SetValueString

func (branch *DataBranch) SetValueString(value ...string) error

func (*DataBranch) SetValueStringSafe

func (branch *DataBranch) SetValueStringSafe(value ...string) error

func (*DataBranch) String

func (branch *DataBranch) String() string

func (*DataBranch) UnmarshalJSON

func (branch *DataBranch) UnmarshalJSON(jbytes []byte) error

func (*DataBranch) UnmarshalXML

func (branch *DataBranch) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

func (*DataBranch) UnmarshalYAML

func (branch *DataBranch) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*DataBranch) UnsetMetadata

func (branch *DataBranch) UnsetMetadata(name string) error

UnsetMetadata() remove a metadata.

func (*DataBranch) UnsetValue

func (branch *DataBranch) UnsetValue(value ...interface{}) error

func (*DataBranch) UnsetValueString

func (branch *DataBranch) UnsetValueString(value ...string) error

func (*DataBranch) Update

func (branch *DataBranch) Update(id string, value ...string) (DataNode, error)

func (*DataBranch) UpdateByMap

func (branch *DataBranch) UpdateByMap(pmap map[string]interface{}) error

UpdateByMap() updates the data node using pmap (path predicate map) and string values.

func (*DataBranch) Value

func (branch *DataBranch) Value() interface{}

func (*DataBranch) ValueString

func (branch *DataBranch) ValueString() string

func (*DataBranch) Values

func (branch *DataBranch) Values() []interface{}

type DataLeaf

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

DataLeaf - The node structure of yangtree for list or leaf-list nodes.

func (*DataLeaf) Child

func (leaf *DataLeaf) Child(index int) DataNode

func (*DataLeaf) Children

func (leaf *DataLeaf) Children() []DataNode

func (*DataLeaf) Create

func (leaf *DataLeaf) Create(id string, value ...string) (DataNode, error)

func (*DataLeaf) CreateByMap

func (leaf *DataLeaf) CreateByMap(pmap map[string]interface{}) error

CreateByMap() updates the data node using pmap (path predicate map) and string values.

func (*DataLeaf) Delete

func (leaf *DataLeaf) Delete(child DataNode) error

func (*DataLeaf) Exist

func (leaf *DataLeaf) Exist(id string) bool

func (*DataLeaf) Get

func (leaf *DataLeaf) Get(id string) DataNode

func (*DataLeaf) GetAll

func (leaf *DataLeaf) GetAll(id string) []DataNode

func (*DataLeaf) GetOrNew

func (leaf *DataLeaf) GetOrNew(id string, insert InsertOption) (DataNode, bool, error)

GetOrNew() gets or creates a node having the id and returns the found or created node with the boolean value that indicates the returned node is created.

func (*DataLeaf) GetValue

func (leaf *DataLeaf) GetValue(id string) interface{}

func (*DataLeaf) GetValueString

func (leaf *DataLeaf) GetValueString(id string) string

func (*DataLeaf) HasMultipleValues

func (leaf *DataLeaf) HasMultipleValues() bool

func (*DataLeaf) HasStateNode

func (leaf *DataLeaf) HasStateNode() bool

func (*DataLeaf) HasValueString

func (leaf *DataLeaf) HasValueString(value string) bool

func (*DataLeaf) ID

func (leaf *DataLeaf) ID() string

func (*DataLeaf) Index

func (leaf *DataLeaf) Index(id string) int

func (*DataLeaf) Insert

func (leaf *DataLeaf) Insert(child DataNode, insert InsertOption) (DataNode, error)

func (*DataLeaf) IsBranchNode

func (leaf *DataLeaf) IsBranchNode() bool

func (*DataLeaf) IsContainer

func (leaf *DataLeaf) IsContainer() bool

func (*DataLeaf) IsDataNode

func (leaf *DataLeaf) IsDataNode()

func (*DataLeaf) IsDuplicatableNode

func (leaf *DataLeaf) IsDuplicatableNode() bool

func (*DataLeaf) IsLeaf

func (leaf *DataLeaf) IsLeaf() bool

func (*DataLeaf) IsLeafList

func (leaf *DataLeaf) IsLeafList() bool

func (*DataLeaf) IsLeafNode

func (leaf *DataLeaf) IsLeafNode() bool

func (*DataLeaf) IsList

func (leaf *DataLeaf) IsList() bool

func (*DataLeaf) IsListableNode

func (leaf *DataLeaf) IsListableNode() bool

func (*DataLeaf) IsNil

func (leaf *DataLeaf) IsNil() bool

func (*DataLeaf) IsStateNode

func (leaf *DataLeaf) IsStateNode() bool

func (*DataLeaf) Len

func (leaf *DataLeaf) Len() int

func (*DataLeaf) Lookup

func (leaf *DataLeaf) Lookup(prefix string) []DataNode

func (*DataLeaf) MarshalJSON

func (leaf *DataLeaf) MarshalJSON() ([]byte, error)

func (*DataLeaf) MarshalXML

func (leaf *DataLeaf) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*DataLeaf) MarshalYAML

func (leaf *DataLeaf) MarshalYAML() (interface{}, error)

func (*DataLeaf) Merge

func (leaf *DataLeaf) Merge(src DataNode) error

Merge() merges the src data node to the leaf data node.

func (*DataLeaf) Metadata

func (leaf *DataLeaf) Metadata() map[string]DataNode

func (*DataLeaf) Name

func (leaf *DataLeaf) Name() string

func (*DataLeaf) Parent

func (leaf *DataLeaf) Parent() DataNode

func (*DataLeaf) Path

func (leaf *DataLeaf) Path() string

func (*DataLeaf) PathTo

func (leaf *DataLeaf) PathTo(descendant DataNode) string

func (*DataLeaf) QName

func (leaf *DataLeaf) QName(rfc7951 bool) (string, bool)

func (*DataLeaf) Remove

func (leaf *DataLeaf) Remove() error

func (*DataLeaf) Replace

func (leaf *DataLeaf) Replace(src DataNode) error

Replace() replaces itself to the src node.

func (*DataLeaf) Schema

func (leaf *DataLeaf) Schema() *SchemaNode

func (*DataLeaf) SetMetadata

func (leaf *DataLeaf) SetMetadata(name string, value ...interface{}) error

SetMetadata() sets a metadata. for example, the following last-modified is set to the node as a metadata.

node.SetMetadata("last-modified", "2015-06-18T17:01:14+02:00")

func (*DataLeaf) SetMetadataString

func (leaf *DataLeaf) SetMetadataString(name string, value ...string) error

SetMetadataString() sets a metadata. for example, the following last-modified is set to the node as a metadata.

node.SetMetadataString("last-modified", "2015-06-18T17:01:14+02:00")

func (*DataLeaf) SetValue

func (leaf *DataLeaf) SetValue(value ...interface{}) error

func (*DataLeaf) SetValueSafe

func (leaf *DataLeaf) SetValueSafe(value ...interface{}) error

func (*DataLeaf) SetValueString

func (leaf *DataLeaf) SetValueString(value ...string) error

func (*DataLeaf) SetValueStringSafe

func (leaf *DataLeaf) SetValueStringSafe(value ...string) error

func (*DataLeaf) String

func (leaf *DataLeaf) String() string

func (*DataLeaf) UnmarshalJSON

func (leaf *DataLeaf) UnmarshalJSON(jbytes []byte) error

func (*DataLeaf) UnmarshalXML

func (leaf *DataLeaf) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

func (*DataLeaf) UnmarshalYAML

func (leaf *DataLeaf) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*DataLeaf) UnsetMetadata

func (leaf *DataLeaf) UnsetMetadata(name string) error

UnsetMetadata() remove a metadata.

func (*DataLeaf) UnsetValue

func (leaf *DataLeaf) UnsetValue(value ...interface{}) error

func (*DataLeaf) UnsetValueString

func (leaf *DataLeaf) UnsetValueString(value ...string) error

func (*DataLeaf) Update

func (leaf *DataLeaf) Update(id string, value ...string) (DataNode, error)

func (*DataLeaf) UpdateByMap

func (leaf *DataLeaf) UpdateByMap(pmap map[string]interface{}) error

UpdateByMap() updates the data node using pmap (path predicate map) and string values.

func (*DataLeaf) Value

func (leaf *DataLeaf) Value() interface{}

func (*DataLeaf) ValueString

func (leaf *DataLeaf) ValueString() string

func (*DataLeaf) Values

func (leaf *DataLeaf) Values() []interface{}

type DataLeafList

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

DataLeafList - The node structure of yangtree for leaf-list nodes. By default, it is not used for the data node representation of the leaf-list nodes. It will be only used when YANGTreeOption.SingleLeafList is enabled.

func (*DataLeafList) Child

func (leaflist *DataLeafList) Child(index int) DataNode

func (*DataLeafList) Children

func (leaflist *DataLeafList) Children() []DataNode

func (*DataLeafList) Create

func (leaflist *DataLeafList) Create(id string, value ...string) (DataNode, error)

func (*DataLeafList) CreateByMap

func (leaflist *DataLeafList) CreateByMap(pmap map[string]interface{}) error

CreateByMap() updates the data node using pmap (path predicate map) and string values.

func (*DataLeafList) Delete

func (leaflist *DataLeafList) Delete(child DataNode) error

func (*DataLeafList) Exist

func (leaflist *DataLeafList) Exist(id string) bool

func (*DataLeafList) Get

func (leaflist *DataLeafList) Get(id string) DataNode

func (*DataLeafList) GetAll

func (leaflist *DataLeafList) GetAll(id string) []DataNode

func (*DataLeafList) GetOrNew

func (leaflist *DataLeafList) GetOrNew(id string, insert InsertOption) (DataNode, bool, error)

GetOrNew() gets or creates a node having the id and returns the found or created node with the boolean value that indicates the returned node is created.

func (*DataLeafList) GetValue

func (leaflist *DataLeafList) GetValue(id string) interface{}

func (*DataLeafList) GetValueString

func (leaflist *DataLeafList) GetValueString(id string) string

func (*DataLeafList) HasMultipleValues

func (leaflist *DataLeafList) HasMultipleValues() bool

func (*DataLeafList) HasStateNode

func (leaflist *DataLeafList) HasStateNode() bool

func (*DataLeafList) HasValueString

func (leaflist *DataLeafList) HasValueString(value string) bool

func (*DataLeafList) ID

func (leaflist *DataLeafList) ID() string

func (*DataLeafList) Index

func (leaflist *DataLeafList) Index(id string) int

func (*DataLeafList) Insert

func (leaflist *DataLeafList) Insert(child DataNode, insert InsertOption) (DataNode, error)

func (*DataLeafList) IsBranchNode

func (leaflist *DataLeafList) IsBranchNode() bool

func (*DataLeafList) IsContainer

func (leaflist *DataLeafList) IsContainer() bool

func (*DataLeafList) IsDataNode

func (leaflist *DataLeafList) IsDataNode()

func (*DataLeafList) IsDuplicatableNode

func (leaflist *DataLeafList) IsDuplicatableNode() bool

func (*DataLeafList) IsLeaf

func (leaflist *DataLeafList) IsLeaf() bool

func (*DataLeafList) IsLeafList

func (leaflist *DataLeafList) IsLeafList() bool

func (*DataLeafList) IsLeafNode

func (leaflist *DataLeafList) IsLeafNode() bool

func (*DataLeafList) IsList

func (leaflist *DataLeafList) IsList() bool

func (*DataLeafList) IsListableNode

func (leaflist *DataLeafList) IsListableNode() bool

func (*DataLeafList) IsNil

func (leaflist *DataLeafList) IsNil() bool

func (*DataLeafList) IsStateNode

func (leaflist *DataLeafList) IsStateNode() bool

func (*DataLeafList) Len

func (leaflist *DataLeafList) Len() int

func (*DataLeafList) Lookup

func (leaflist *DataLeafList) Lookup(prefix string) []DataNode

func (*DataLeafList) MarshalJSON

func (leaflist *DataLeafList) MarshalJSON() ([]byte, error)

func (*DataLeafList) MarshalXML

func (leaflist *DataLeafList) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*DataLeafList) MarshalYAML

func (leaflist *DataLeafList) MarshalYAML() (interface{}, error)

func (*DataLeafList) Merge

func (leaflist *DataLeafList) Merge(src DataNode) error

Merge() merges the src data node to the leaflist data node.

func (*DataLeafList) Metadata

func (leaflist *DataLeafList) Metadata() map[string]DataNode

func (*DataLeafList) Name

func (leaflist *DataLeafList) Name() string

func (*DataLeafList) Parent

func (leaflist *DataLeafList) Parent() DataNode

func (*DataLeafList) Path

func (leaflist *DataLeafList) Path() string

func (*DataLeafList) PathTo

func (leaflist *DataLeafList) PathTo(descendant DataNode) string

func (*DataLeafList) QName

func (leaflist *DataLeafList) QName(rfc7951 bool) (string, bool)

func (*DataLeafList) Remove

func (leaflist *DataLeafList) Remove() error

func (*DataLeafList) Replace

func (leaflist *DataLeafList) Replace(src DataNode) error

Replace() replaces itself to the src node.

func (*DataLeafList) Schema

func (leaflist *DataLeafList) Schema() *SchemaNode

func (*DataLeafList) SetMetadata

func (leaflist *DataLeafList) SetMetadata(name string, value ...interface{}) error

SetMetadata() sets a metadata. for example, the following last-modified is set to the node as a metadata.

node.SetMetadata("last-modified", "2015-06-18T17:01:14+02:00")

func (*DataLeafList) SetMetadataString

func (leaflist *DataLeafList) SetMetadataString(name string, value ...string) error

SetMetadataString() sets a metadata. for example, the following last-modified is set to the node as a metadata.

node.SetMetadataString("last-modified", "2015-06-18T17:01:14+02:00")

func (*DataLeafList) SetValue

func (leaflist *DataLeafList) SetValue(value ...interface{}) error

func (*DataLeafList) SetValueSafe

func (leaflist *DataLeafList) SetValueSafe(value ...interface{}) error

func (*DataLeafList) SetValueString

func (leaflist *DataLeafList) SetValueString(value ...string) error

func (*DataLeafList) SetValueStringSafe

func (leaflist *DataLeafList) SetValueStringSafe(value ...string) error

func (*DataLeafList) String

func (leaflist *DataLeafList) String() string

func (*DataLeafList) UnmarshalJSON

func (leaflist *DataLeafList) UnmarshalJSON(jbytes []byte) error

func (*DataLeafList) UnmarshalXML

func (leaflist *DataLeafList) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

func (*DataLeafList) UnmarshalYAML

func (leaflist *DataLeafList) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*DataLeafList) UnsetMetadata

func (leaflist *DataLeafList) UnsetMetadata(name string) error

UnsetMetadata() remove a metadata.

func (*DataLeafList) UnsetValue

func (leaflist *DataLeafList) UnsetValue(value ...interface{}) error

func (*DataLeafList) UnsetValueString

func (leaflist *DataLeafList) UnsetValueString(value ...string) error

func (*DataLeafList) Update

func (leaflist *DataLeafList) Update(id string, value ...string) (DataNode, error)

func (*DataLeafList) UpdateByMap

func (leaflist *DataLeafList) UpdateByMap(pmap map[string]interface{}) error

UpdateByMap() updates the data node using pmap (path predicate map) and string values.

func (*DataLeafList) Value

func (leaflist *DataLeafList) Value() interface{}

func (*DataLeafList) ValueString

func (leaflist *DataLeafList) ValueString() string

FIXME - Incomplete conversion to string

func (*DataLeafList) Values

func (leaflist *DataLeafList) Values() []interface{}

type DataNode

type DataNode interface {
	IsDataNode()
	IsNil() bool              // IsNil() is used to check the data node is null.
	IsBranchNode() bool       // IsBranchNode() returns true if the data node is a DataBranch (a container or a list node).
	IsLeafNode() bool         // IsLeafNode() returns true if the data node is a DataLeaf (a leaf or a multiple leaf-list node) or DataLeafList (a single leaf-list node).
	IsDuplicatableNode() bool // IsDuplicatable() returns true if multiple nodes having the same ID can exist in the tree.
	IsListableNode() bool     // IsListable() returns true if the nodes that has the same schema are listed in the tree.
	IsStateNode() bool        // IsStateNode() returns true if the node is a config=false node.
	HasStateNode() bool       // HasStateNode() returns true if the node has a config=false child node.
	HasMultipleValues() bool  // HasMultipleValues() returns true if the node has a set of values (= *DataLeafList).

	IsLeaf() bool      // IsLeaf() returns true if the data node is an yang leaf.
	IsLeafList() bool  // IsLeafList() returns true if the data node is an yang leaf-list.
	IsList() bool      // IsList() returns true if the data node is an yang list.
	IsContainer() bool // IsContainer returns true if the data node is an yang container node.

	Name() string                      // Name() returns the name of the data node.
	QName(rfc7951 bool) (string, bool) // QName() returns the namespace-qualified name e.g. module-name:node-name or module-prefix:node-name.
	ID() string                        // ID() returns the data node ID (NODE[KEY=VALUE]). The ID is an XPath element combined with XPath predicates to identify the node instance.

	Schema() *SchemaNode  // Schema() returns the schema of the data node.
	Parent() DataNode     // Parent() returns the parent if it is present.
	Children() []DataNode // Children() returns all child nodes.

	Insert(child DataNode, i InsertOption) (DataNode, error) // Insert() inserts a new child node. It replaces and returns the old one.
	Delete(child DataNode) error                             // Delete() deletes the child node if it is present.
	Replace(src DataNode) error                              // Replace() replaces itself to the src node.
	Merge(src DataNode) error                                // Merge() merges the src node including all children to the current data node.
	Remove() error                                           // Remove() removes itself.

	// GetOrNew() gets or creates a node having the id (NODE_NAME or NODE_NAME[KEY=VALUE]) and returns
	// the found or created node with the boolean value that
	// indicates the returned node is created.
	GetOrNew(id string, i InsertOption) (DataNode, bool, error)

	Create(id string, value ...string) (DataNode, error) // Create() creates a child using the node id (NODE_NAME or NODE_NAME[KEY=VALUE]).
	Update(id string, value ...string) (DataNode, error) // Update() updates a child that has the node id (NODE_NAME or NODE_NAME[KEY=VALUE]) using the input values.

	CreateByMap(pmap map[string]interface{}) error // CreateByMap() updates the data node using pmap (path predicate map) and string values.
	UpdateByMap(pmap map[string]interface{}) error // UpdateByMap() updates the data node using pmap (path predicate map) and string values.

	Exist(id string) bool              // Exist() is used to check a data node is present.
	Get(id string) DataNode            // Get() is used to get the first child has the id.
	GetValue(id string) interface{}    // GetValue() is used to get the value of the child that has the id.
	GetValueString(id string) string   // GetValueString() is used to get the value, converted to string, of the child that has the id.
	GetAll(id string) []DataNode       // GetAll() is used to get all children that have the id.
	Lookup(idPrefix string) []DataNode // Lookup() is used to get all children on which their keys start with the prefix string of the node id.

	Len() int                 // Len() returns the number of children or the number of values.
	Index(id string) int      // Index() finds all children by the node id and returns the position.
	Child(index int) DataNode // Child() gets the child of the index.

	String() string                    // String() returns a string to identify the node.
	Path() string                      // Path() returns the path from the root to the current data node.
	PathTo(descendant DataNode) string // PathTo() returns a relative path to a descendant node.

	SetValue(value ...interface{}) error     // SetValue() writes the values to the data node.
	SetValueSafe(value ...interface{}) error // SetValueSafe() writes the values to the data node. It will recover the value if failed.
	UnsetValue(value ...interface{}) error   // UnsetValue() clear the value of the data node to the default.

	SetValueString(value ...string) error     // SetValueString() writes the values to the data node. The value must be string.
	SetValueStringSafe(value ...string) error // SetValueStringSafe() writes the values to the data node. It will recover the value if failed.
	UnsetValueString(value ...string) error   // UnsetValueString() clear the value of the data node to the default.
	HasValueString(value string) bool         // HasValueString() returns true if the data node value has the value.

	Value() interface{}    // Value() returns the raw data of the data node.
	Values() []interface{} // Values() returns its values using []interface{} slice
	ValueString() string   // ValueString() returns the string value of the data node.

	SetMetadata(name string, value ...interface{}) error  // SetMetadata() sets a metadata.
	SetMetadataString(name string, value ...string) error // SetMetadataString() sets a metadata using string values.
	UnsetMetadata(name string) error                      // UnsetMetadata() remove a metadata.

	// Metadata(name string) interface{}
	// Metadatas(name string) []interface{}
	Metadata() map[string]DataNode
}

yangtree consists of the data node.

func Clone

func Clone(src DataNode) DataNode

Clone() copies the src data node with its all decendants.

func DiffCreated

func DiffCreated(node1, node2 DataNode, disDupCmp bool) []DataNode

DiffCreated() returns created nodes. It returns all created nodes in node2 (including itself) against node1. The deleted nodes can be obtained by the reverse input.

func Find

func Find(root DataNode, path string, option ...Option) ([]DataNode, error)

Find() finds all data nodes in the path. xpath format can be used for the path as following example.

Find(root, "//path/to/data[name='xxx']", UseXPath{})

func FindAllInRoute

func FindAllInRoute(path string) []DataNode

FindAllInRoute() find all parent nodes in the path. The path must indicate an unique node. (not support wildcard and multiple node selection)

func New

func New(schema *SchemaNode) (DataNode, error)

New() creates a new DataNode (*DataBranch or *DataLeaf) according to the schema.

func NewCollector

func NewCollector() DataNode

NewCollector() creates a fake node that can be used to collect all kindes of data nodes. Any of data nodes can be contained to the collector data node.

func NewWithID

func NewWithID(schema *SchemaNode, id string) (DataNode, error)

NewWithID() creates a new DataNode using id (NODE_NAME or NODE_NAME[KEY=VALUE])

func NewWithValue

func NewWithValue(schema *SchemaNode, value ...interface{}) (DataNode, error)

NewWithValue() creates a new DataNode (*DataBranch or *DataLeaf) according to the schema with its values. The values should be a string if the new DataNode is *DataLeaf, *DataLeafList. The values should be JSON encoded bytes if the node is *DataBranch.

func NewWithValueString

func NewWithValueString(schema *SchemaNode, value ...string) (DataNode, error)

NewWithValueString() creates a new DataNode (*DataBranch or *DataLeaf) according to the schema with its values. The values should be a string if the new DataNode is *DataLeaf, *DataLeafList. The values should be JSON encoded bytes if the node is *DataBranch.

type DataNodeGroup

type DataNodeGroup struct {
	Nodes []DataNode
	// contains filtered or unexported fields
}

A set of data nodes that have the same schema.

func ConvertToGroup

func ConvertToGroup(schema *SchemaNode, nodes []DataNode) (*DataNodeGroup, error)

ConvertToGroup() creates a set of new data nodes (DataNodeGroup) having the same schema. To create a set of data nodes, the value must be encoded to a JSON object or a JSON array of the data. It is useful to create multiple list or leaf-list nodes.

// e.g.
groups, err := NewGroupWithValueString(schema, `["leaf-list-value1", "leaf-list-value2"]`)
for _, node := range groups {
     // Process the created nodes ("leaf-list-value1" and "leaf-list-value2") here.
}

func NewGroupWithValue

func NewGroupWithValue(schema *SchemaNode, value ...interface{}) (*DataNodeGroup, error)

NewGroupWithValue() creates a set of new data nodes (*DataNodeGroup) having the same schema. To create a set of data nodes, the value must be encoded to a JSON object or a JSON array of the data. It is useful to create multiple list or leaf-list nodes.

// e.g.
groups, err := NewGroupWithValue(schema, `["leaf-list-value1", "leaf-list-value2"]`)
for _, node := range groups.Nodes {
     // Process the created nodes ("leaf-list-value1" and "leaf-list-value2") here.
}

func NewGroupWithValueString

func NewGroupWithValueString(schema *SchemaNode, value ...string) (*DataNodeGroup, error)

NewGroupWithValueString() creates a set of new data nodes (*DataNodeGroup) having the same schema. To create a set of data nodes, the value must be encoded to a JSON object or a JSON array of the data. It is useful to create multiple list or leaf-list nodes.

// e.g.
groups, err := NewGroupWithValueString(schema, `["leaf-list-value1", "leaf-list-value2"]`)
for _, node := range groups.Nodes {
     // Process the created nodes ("leaf-list-value1" and "leaf-list-value2") here.
}

func (*DataNodeGroup) Child

func (group *DataNodeGroup) Child(index int) DataNode

func (*DataNodeGroup) Children

func (group *DataNodeGroup) Children() []DataNode

func (*DataNodeGroup) Create

func (group *DataNodeGroup) Create(id string, value ...string) (DataNode, error)

func (*DataNodeGroup) CreateByMap

func (group *DataNodeGroup) CreateByMap(pmap map[string]interface{}) error

CreateByMap() updates the data node using pmap (path predicate map) and string values.

func (*DataNodeGroup) Delete

func (group *DataNodeGroup) Delete(child DataNode) error

func (*DataNodeGroup) Exist

func (group *DataNodeGroup) Exist(id string) bool

func (*DataNodeGroup) Get

func (group *DataNodeGroup) Get(id string) DataNode

func (*DataNodeGroup) GetAll

func (group *DataNodeGroup) GetAll(id string) []DataNode

func (*DataNodeGroup) GetOrNew

func (group *DataNodeGroup) GetOrNew(id string, insert InsertOption) (DataNode, bool, error)

GetOrNew() gets or creates a node having the id and returns the found or created node with the boolean value that indicates the returned node is created.

func (*DataNodeGroup) GetValue

func (group *DataNodeGroup) GetValue(id string) interface{}

func (*DataNodeGroup) GetValueString

func (group *DataNodeGroup) GetValueString(id string) string

func (*DataNodeGroup) HasMultipleValues

func (group *DataNodeGroup) HasMultipleValues() bool

func (*DataNodeGroup) HasStateNode

func (group *DataNodeGroup) HasStateNode() bool

func (*DataNodeGroup) HasValueString

func (group *DataNodeGroup) HasValueString(value string) bool

func (*DataNodeGroup) ID

func (group *DataNodeGroup) ID() string

func (*DataNodeGroup) Index

func (group *DataNodeGroup) Index(id string) int

func (*DataNodeGroup) Insert

func (group *DataNodeGroup) Insert(child DataNode, insert InsertOption) (DataNode, error)

func (*DataNodeGroup) IsBranchNode

func (group *DataNodeGroup) IsBranchNode() bool

func (*DataNodeGroup) IsContainer

func (group *DataNodeGroup) IsContainer() bool

func (*DataNodeGroup) IsDataNode

func (group *DataNodeGroup) IsDataNode()

func (*DataNodeGroup) IsDuplicatableNode

func (group *DataNodeGroup) IsDuplicatableNode() bool

func (*DataNodeGroup) IsLeaf

func (group *DataNodeGroup) IsLeaf() bool

func (*DataNodeGroup) IsLeafList

func (group *DataNodeGroup) IsLeafList() bool

func (*DataNodeGroup) IsLeafNode

func (group *DataNodeGroup) IsLeafNode() bool

func (*DataNodeGroup) IsList

func (group *DataNodeGroup) IsList() bool

func (*DataNodeGroup) IsListableNode

func (group *DataNodeGroup) IsListableNode() bool

func (*DataNodeGroup) IsNil

func (group *DataNodeGroup) IsNil() bool

func (*DataNodeGroup) IsStateNode

func (group *DataNodeGroup) IsStateNode() bool

func (*DataNodeGroup) Len

func (group *DataNodeGroup) Len() int

func (*DataNodeGroup) Lookup

func (group *DataNodeGroup) Lookup(prefix string) []DataNode

func (*DataNodeGroup) MarshalJSON

func (group *DataNodeGroup) MarshalJSON() ([]byte, error)

func (*DataNodeGroup) MarshalXML

func (group *DataNodeGroup) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*DataNodeGroup) MarshalYAML

func (group *DataNodeGroup) MarshalYAML() (interface{}, error)

func (*DataNodeGroup) Merge

func (group *DataNodeGroup) Merge(src DataNode) error

Merge() merges the src data node to the leaf data node.

func (*DataNodeGroup) Metadata

func (group *DataNodeGroup) Metadata() map[string]DataNode

func (*DataNodeGroup) Name

func (group *DataNodeGroup) Name() string

func (*DataNodeGroup) Parent

func (group *DataNodeGroup) Parent() DataNode

func (*DataNodeGroup) Path

func (group *DataNodeGroup) Path() string

func (*DataNodeGroup) PathTo

func (group *DataNodeGroup) PathTo(descendant DataNode) string

func (*DataNodeGroup) QName

func (group *DataNodeGroup) QName(rfc7951 bool) (string, bool)

func (*DataNodeGroup) Remove

func (group *DataNodeGroup) Remove() error

func (*DataNodeGroup) Replace

func (group *DataNodeGroup) Replace(src DataNode) error

Replace() replaces itself to the src node.

func (*DataNodeGroup) Schema

func (group *DataNodeGroup) Schema() *SchemaNode

func (*DataNodeGroup) SetMetadata

func (group *DataNodeGroup) SetMetadata(name string, value ...interface{}) error

SetMetadata() sets a metadata. for example, the following last-modified is set to the node as a metadata.

node.SetMetadata("last-modified", "2015-06-18T17:01:14+02:00")

func (*DataNodeGroup) SetMetadataString

func (group *DataNodeGroup) SetMetadataString(name string, value ...string) error

SetMetadataString() sets a metadata. for example, the following last-modified is set to the node as a metadata.

node.SetMetadataString("last-modified", "2015-06-18T17:01:14+02:00")

func (*DataNodeGroup) SetValue

func (group *DataNodeGroup) SetValue(value ...interface{}) error

func (*DataNodeGroup) SetValueSafe

func (group *DataNodeGroup) SetValueSafe(value ...interface{}) error

func (*DataNodeGroup) SetValueString

func (group *DataNodeGroup) SetValueString(value ...string) error

func (*DataNodeGroup) SetValueStringSafe

func (group *DataNodeGroup) SetValueStringSafe(value ...string) error

func (*DataNodeGroup) String

func (group *DataNodeGroup) String() string

func (*DataNodeGroup) UnmarshalJSON

func (group *DataNodeGroup) UnmarshalJSON(jbytes []byte) error

func (*DataNodeGroup) UnmarshalXML

func (group *DataNodeGroup) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

func (*DataNodeGroup) UnmarshalYAML

func (group *DataNodeGroup) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*DataNodeGroup) UnsetMetadata

func (group *DataNodeGroup) UnsetMetadata(name string) error

UnsetMetadata() remove a metadata.

func (*DataNodeGroup) UnsetValue

func (group *DataNodeGroup) UnsetValue(value ...interface{}) error

func (*DataNodeGroup) UnsetValueString

func (group *DataNodeGroup) UnsetValueString(value ...string) error

func (*DataNodeGroup) Update

func (group *DataNodeGroup) Update(id string, value ...string) (DataNode, error)

func (*DataNodeGroup) UpdateByMap

func (group *DataNodeGroup) UpdateByMap(pmap map[string]interface{}) error

UpdateByMap() updates the data node using pmap (path predicate map) and string values.

func (*DataNodeGroup) Value

func (group *DataNodeGroup) Value() interface{}

func (*DataNodeGroup) ValueString

func (group *DataNodeGroup) ValueString() string

func (*DataNodeGroup) Values

func (group *DataNodeGroup) Values() []interface{}

type EditOp

type EditOp int

EditOperation [EditMerge, EditCreate, EditReplace, EditDelete, EditRemove] for yangtree

const (
	EditMerge   EditOp = iota // similar to NETCONF edit-config: merge operation
	EditCreate                // similar to NETCONF edit-config: create operation
	EditReplace               // similar to NETCONF edit-config: replace operation
	EditDelete                // similar to NETCONF edit-config: delete operation
	EditRemove                // similar to NETCONF edit-config: remove operation
)

func (EditOp) IsOption

func (op EditOp) IsOption()

func (EditOp) String

func (op EditOp) String() string

type EditOption

type EditOption struct {
	EditOp                                                     // EditOperation
	InsertOption                                               // Insert option for ordered-by yang option
	Callback        func(op EditOp, old, new []DataNode) error // Callback is invoked upon the node changes.
	FailureRecovery bool
}

EditOption is used for yangtree set operation.

func (*EditOption) GetCallback

func (edit *EditOption) GetCallback() func(EditOp, []DataNode, []DataNode) error

func (*EditOption) GetFailureRecovery

func (edit *EditOption) GetFailureRecovery() bool

func (*EditOption) GetInsertOption

func (edit *EditOption) GetInsertOption() InsertOption

func (*EditOption) GetOperation

func (edit *EditOption) GetOperation() EditOp

func (EditOption) IsOption

func (edit EditOption) IsOption()

func (*EditOption) String

func (edit *EditOption) String() string

type ErrorTag

type ErrorTag int
const (
	ETagInUse ErrorTag = iota
	ETagInvalidValue
	ETagTooBig
	ETagMissingAttribute
	ETagBadAttribute
	ETagUnknownAttribute
	ETagMissingElement
	ETagBadElement
	ETagUnknownElement
	ETagUnknownNamespace
	ETagAccessDenied
	ETagLockDenied
	ETagResourceDenied
	ETagRollbackFailed
	ETagDataExists
	ETagDataMissing
	ETagOperationNotSupported
	ETagOperationFailed
	ETagPartialOperation
	ETagMarlformedMessage

	EAppTagUnknownError ErrorTag = iota + 100
	EAppTagDataNodeMissing
	EAppTagDataNodeExists
	EAppTagInvalidArg
	EAppTagJSONParsing
	EAppTagJSONEmitting
	EAppTagYAMLParsing
	EAppTagYAMLEmitting
)

func (ErrorTag) String

func (et ErrorTag) String() string

type ErrorType

type ErrorType int
const (
	ETypeApplication ErrorType = iota
	ETypeProtocol
	ETypeRPC
	ETypeTransport
)

func (ErrorType) String

func (et ErrorType) String() string

type Extension

type Extension struct {
	ExtSchema      map[string]*SchemaNode
	MetadataSchema map[string]*SchemaNode
}

type HasState

type HasState struct{}

HasState option is used to find state data nodes and data nodes having state data nodes.

func (HasState) IsOption

func (f HasState) IsOption()

func (HasState) String

func (f HasState) String() string

type InsertOption

type InsertOption interface {
	GetInsertKey() string
	String() string
}

type InsertToAfter

type InsertToAfter struct {
	Key string
}

func (InsertToAfter) GetInsertKey

func (o InsertToAfter) GetInsertKey() string

func (InsertToAfter) String

func (o InsertToAfter) String() string

type InsertToBefore

type InsertToBefore struct {
	Key string
}

func (InsertToBefore) GetInsertKey

func (o InsertToBefore) GetInsertKey() string

func (InsertToBefore) String

func (o InsertToBefore) String() string

type InsertToFirst

type InsertToFirst struct{}

func (InsertToFirst) GetInsertKey

func (o InsertToFirst) GetInsertKey() string

func (InsertToFirst) String

func (o InsertToFirst) String() string

type InsertToLast

type InsertToLast struct{}

func (InsertToLast) GetInsertKey

func (o InsertToLast) GetInsertKey() string

func (InsertToLast) String

func (o InsertToLast) String() string

type InternalFormat

type InternalFormat struct{}

InternalFormat is an option to marshal a data node to an internal YAML format.

func (InternalFormat) IsOption

func (o InternalFormat) IsOption()

type Metadata

type Metadata struct{}

Metadata option is used to print out the metadata of the tree.

func (Metadata) IsOption

func (metadata Metadata) IsOption()

type MultipleError

type MultipleError []error

func (MultipleError) Error

func (me MultipleError) Error() string

type NodeSelect

type NodeSelect int
const (
	NodeSelectChild       NodeSelect = iota // select the child nodes using the element name and predicate
	NodeSelectSelf                          // if the path starts with `.`
	NodeSelectFromRoot                      // if the path starts with `/`
	NodeSelectAll                           // if the path starts with `//` or `...`
	NodeSelectParent                        // if the path starts with `..`
	NodeSelectAllChildren                   // Wildcard '*'
)

type Option

type Option interface {
	IsOption()
}

yangtree Option

type PathNode

type PathNode struct {
	Prefix     string // used to save the prefix of the data node
	Name       string // used to save the name of the data node
	Value      string // used to save the value of the data node
	Select     NodeSelect
	Predicates []string // used to filter the selected data node set.
}

func ParsePath

func ParsePath(path *string) ([]*PathNode, error)

ParsePath parses the input xpath and return a single element with its attrs.

func (*PathNode) PredicatesToMap

func (pathnode *PathNode) PredicatesToMap() (map[string]interface{}, error)

func (*PathNode) ToMap

func (pathnode *PathNode) ToMap() (map[string]interface{}, error)

type RFC7951Format

type RFC7951Format struct{}

func (RFC7951Format) IsOption

func (f RFC7951Format) IsOption()

type RFC7951S

type RFC7951S int

RFC7951S (rfc7951 processing status)

const (
	// rfc7951disabled - rfc7951 encoding disabled
	RFC7951Disabled RFC7951S = iota
	// RFC7951InProgress - rfc7951 encoding is in progress
	RFC7951InProgress
	// RFC7951Enabled - rfc7951 encoding enabled
	RFC7951Enabled
)

func (RFC7951S) String

func (s RFC7951S) String() string

type ReadCallback

type ReadCallback func(cur DataNode) interface{}

ReadCallback is a callback executed upon reading or marshaling the data of the node.

readList := []string{}
SetValue(root, "/sample/str-val", nil, func(cur DataNode) interface{} {
	readList = append(readList, cur.String())
	return nil
})

type RepresentItself

type RepresentItself struct{}

RepresentItself option is used to print out a top node itself to a json or yaml document.

  enumSchema := RootSchema.FindSchema("/sample/container-val/enum-val")
	 datanode, _ := NewWithValue(enumSchema, "enum1")
	 if j, _ := MarshalJSON(datanode); len(j) > 0 {
	 	fmt.Println(string(j))
	 	// "enum1"
	 }
	 if j, _ := MarshalJSON(datanode, RepresentItself{}); len(j) > 0 {
	 	fmt.Println(string(j))
	 	// {"enum-val":"enum1"}
	 }

func (RepresentItself) IsOption

func (f RepresentItself) IsOption()

type SchemaNode

type SchemaNode struct {
	*yang.Entry
	Parent        *SchemaNode            // The parent schema node of the schema node
	Module        *yang.Module           // The module of the schema node
	Children      []*SchemaNode          // The child schema nodes of the schema node
	Directory     map[string]*SchemaNode // used to store the children of the schema node with all schema node's aliases
	Enum          map[string]int64       // used to store all enumeration string
	Bits          map[string]int64
	BitsR         map[int64]string
	Identityref   map[string]*yang.Module // used to store all identity values of the schema node
	Keyname       []string                // used to store key list
	Qboundary     bool                    // used to indicate the boundary of the namespace-qualified name of RFC7951
	IsRoot        bool                    // used to indicate the schema is the root of the schema tree.
	IsKey         bool                    // used to indicate the schema node is a key node of a list.
	IsState       bool                    // used to indicate the schema node is state node.
	HasState      bool                    // used to indicate the schema node has a state node at least.
	OrderedByUser bool                    // used to indicate the ordering of the list or the leaf-list nodes.
	Option        *YANGTreeOption
	Modules       *yang.Modules
	*Extension

	// Set option
	ContainAny bool
}

SchemaNode - The node structure of yangtree schema.

func CollectSchemaEntries

func CollectSchemaEntries(e *SchemaNode, leafOnly bool) []*SchemaNode

CollectSchemaEntries returns all entries of the schema tree.

func Load

func Load(file, dir, excluded []string, option ...Option) (*SchemaNode, error)

Load() loads all yang files and then build the schema tree of the files. dir is reference directories for imported or included yang files. excluded is yang module names to be excluded.

func (*SchemaNode) Append

func (schema *SchemaNode) Append(changeParent bool, nodes ...*SchemaNode) error

Append() adds the nodes to the schema node as child nodes. If the changeParent is set, the Parent of each child becomes the scema node. This affacts the schema tree of a yangtree.

func (*SchemaNode) FindSchema

func (schema *SchemaNode) FindSchema(path string) *SchemaNode

FindSchema() returns a descendant schema node in the path.

func (*SchemaNode) GenerateID

func (schema *SchemaNode) GenerateID(pmap map[string]interface{}) (string, bool, bool)

GenerateID generates the node ID of the schema using the value in the pmap. It also returns a boolean value to true if the ID is used for the access of multiple data nodes.

func (*SchemaNode) GetMust

func (schema *SchemaNode) GetMust() []*yang.Must

GetMust() returns the "must" statements of the schema node.

func (*SchemaNode) GetNamespaceAndPrefix

func (schema *SchemaNode) GetNamespaceAndPrefix() (string, string)

func (*SchemaNode) GetQName

func (schema *SchemaNode) GetQName(rfc7951 bool) (string, bool)

GetQName() returns the qname (namespace-qualified name e.g. module-name:node-name) of the schema node.

func (*SchemaNode) GetRootSchema

func (schema *SchemaNode) GetRootSchema() *SchemaNode

GetRootSchema() returns its root schema node.

func (*SchemaNode) GetSchema

func (schema *SchemaNode) GetSchema(name string) *SchemaNode

GetSchema() returns a child of the schema node. The namespace-qualified name is used for the name.

func (*SchemaNode) GetYangLibrary

func (schema *SchemaNode) GetYangLibrary() DataNode

func (*SchemaNode) HasRPCInput

func (schema *SchemaNode) HasRPCInput() bool

func (*SchemaNode) HasRPCOutput

func (schema *SchemaNode) HasRPCOutput() bool

func (*SchemaNode) IsAnyData

func (schema *SchemaNode) IsAnyData() bool

IsAnyData() returns true if the schema node is anydata.

func (*SchemaNode) IsDuplicatable

func (schema *SchemaNode) IsDuplicatable() bool

IsDuplicatable() checks the data nodes can be inserted duplicately several times.

func (*SchemaNode) IsDuplicatableList

func (schema *SchemaNode) IsDuplicatableList() bool

IsDuplicatableList() checks the data nodes is a list node and it can be inserted duplicately.

func (*SchemaNode) IsListHasKey

func (schema *SchemaNode) IsListHasKey() bool

IsListHasKey() checks the list nodes has keys.

func (*SchemaNode) IsListable

func (schema *SchemaNode) IsListable() bool

IsListable() checks if the schema node is a list or a leaf-list node. If SingleLeafList is set, it is not lisable because it has serveral values in the single leaf-list node.

func (*SchemaNode) IsOrderedByUser

func (schema *SchemaNode) IsOrderedByUser() bool

IsOrderedByUser() is used to check the node is ordered by the user.

func (*SchemaNode) IsRPC

func (schema *SchemaNode) IsRPC() bool

func (*SchemaNode) IsSingleLeafList

func (schema *SchemaNode) IsSingleLeafList() bool

IsSingleLeafList() returns true if the schema node is single leaf-list schema.

func (*SchemaNode) IsValidQName

func (schema *SchemaNode) IsValidQName(qname *string, rfc7951 bool) bool

IsValidQName() returns true if the qualified name is valid.

func (*SchemaNode) Path

func (schema *SchemaNode) Path() string

Path() generates the schema path of the schema node.

func (*SchemaNode) QualifiedPath

func (schema *SchemaNode) QualifiedPath(RFC7951format bool) string

QualifiedPath() generates the qualified schema path of the schema node.

func (*SchemaNode) String

func (schema *SchemaNode) String() string

func (*SchemaNode) ValueToJSONBytes

func (schema *SchemaNode) ValueToJSONBytes(typ *yang.YangType, value interface{}, rfc7951format bool) ([]byte, error)

ValueToJSONBytes() marshals a value based on its schema, type and representing format.

func (*SchemaNode) ValueToQValue

func (schema *SchemaNode) ValueToQValue(typ *yang.YangType, value interface{}, rfc7951format bool) (interface{}, error)

ValueToQValue returns the raw value using namespace-qualified format.

func (*SchemaNode) ValueToYAMLBytes

func (schema *SchemaNode) ValueToYAMLBytes(typ *yang.YangType, value interface{}, rfc7951 bool) ([]byte, error)

ValueToYAMLBytes encodes the value to a YAML-encoded data. the schema and the type of the value must be set.

type StateOnly

type StateOnly struct{}

StateOnly option is used to find state data nodes that have "config false" statement.

func (StateOnly) IsOption

func (f StateOnly) IsOption()

func (StateOnly) String

func (f StateOnly) String() string

type TrvsCallOption

type TrvsCallOption int

TrvsCallOption is an argument of Traverse() to decide where user-defined traverser() is called.

  • TrvsCalledAtEnter TrvsCallOption // call user-defined traverser() at the entrance of of child nodes.
  • TrvsCalledAtExit // call user-defined traverser() at the exit of of child nodes.
  • TrvsCalledAtEnterAndExit // call user-defined traverser() at the entrance and exit of child nodes.
const (
	TrvsCalledAtEnter        TrvsCallOption = 0 // call user-defined traverser() at the entrance of of child nodes.
	TrvsCalledAtExit         TrvsCallOption = 2 // call user-defined traverser() at the exit of of child nodes.
	TrvsCalledAtEnterAndExit TrvsCallOption = 1 // call user-defined traverser() at the entrance and exit of child nodes.
)

type UseXPath

type UseXPath struct{}

func (UseXPath) IsOption

func (useXpath UseXPath) IsOption()

type YANGTreeOption

type YANGTreeOption struct {
	// If SingleLeafList is enabled, leaf-list data represents to a single leaf-list node that contains several values.
	// If disabled, leaf-list data represents to multiple leaf-list nodes that contains each single value.
	SingleLeafList     bool
	LeafListValueAsKey bool   // leaf-list value can be represented to the xpath if it is set to true.
	CreatedWithDefault bool   // DataNode (data node) is created with the default value of the schema if set.
	YANGLibrary2016    bool   // Load ietf-yang-library@2016-06-21
	YANGLibrary2019    bool   // Load ietf-yang-library@2019-01-04
	SchemaSetName      string // The name of the schema set

}

YANGTreeOption is used to store yangtree options.

func (YANGTreeOption) IsOption

func (yangtreeOption YANGTreeOption) IsOption()

type YError

type YError struct {
	ErrorTag
	// ErrorAppTag ErrorTag
	ErrorType
	ErrorMessage string
}

func (*YError) Error

func (ye *YError) Error() string

Directories

Path Synopsis
examples
set
tozip - generates go byte arrary of the input yang files.
tozip - generates go byte arrary of the input yang files.

Jump to

Keyboard shortcuts

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