node

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 15 Imported by: 24

Documentation

Overview

Package node gives you base structures to capture how to read, write, execute and listen for events from your application.

Index

Constants

This section is empty.

Variables

View Source
var ErrNilSelection = errors.New("selection is nil")
View Source
var NO_VALUE reflect.Value

Functions

func EncodeKey

func EncodeKey(v []val.Value) string

func NewValue

func NewValue(typ *meta.Type, v interface{}) (val.Value, error)

Incoming value should be of appropriate type according to given data type format

func NewValues

func NewValues(m []meta.Leafable, objs ...interface{}) ([]val.Value, error)

func NewValuesByString

func NewValuesByString(m []meta.Leafable, objs ...string) ([]val.Value, error)

Types

type ActionPostConstraint

type ActionPostConstraint interface {
	CheckActionPostConstraints(r ActionRequest) (bool, error)
}

type ActionPreConstraint

type ActionPreConstraint interface {
	CheckActionPreConstraints(r *ActionRequest) (bool, error)
}

type ActionRequest

type ActionRequest struct {
	Request
	Meta  *meta.Rpc
	Input *Selection
}

type Browser

type Browser struct {

	// Information model of browser
	Meta *meta.Module

	// Regsitry of listeners when data model under browser is modified
	Triggers *TriggerTable

	// True if you want no leaf data checks like pattern, length, range, etc
	// you would only want to do this if you had a good reason
	DisableConstraints bool
	// contains filtered or unexported fields
}

Browser is a handle to a data source and starting point for interfacing with any freeconf enabled interface. It's the starting point to the top-most selection, or the Root().

func NewBrowser

func NewBrowser(m *meta.Module, n Node) *Browser

NewBrowser obviously does not resolve the source node for each new selection so the state of at least the root node is shared for all subsequent operations. In short, either do not keep a copy of this very browser for very long or know what you're doing

func NewBrowserSource

func NewBrowserSource(m *meta.Module, src func() Node) *Browser

NewBrowserSource unites a model (MetaList) with a data source (Node). Here the node instance is requested for each browse operation allowing the node state to be fresh for each request.

func (*Browser) Root

func (self *Browser) Root() *Selection

Root is top-most selection. From here you can use Find to navigate to other parts of application or any of the Insert command to start getting data in or out.

func (*Browser) RootWithContext

func (self *Browser) RootWithContext(ctx context.Context) *Selection

Root is top-most selection. From here you can use Find to navigate to other parts of application or any of the Insert command to start getting data in or out.

type CheckWhen

type CheckWhen struct {
}

func (CheckWhen) CheckContainerPostConstraints

func (y CheckWhen) CheckContainerPostConstraints(r ChildRequest, s *Selection) (bool, error)

func (CheckWhen) CheckFieldPreConstraints

func (y CheckWhen) CheckFieldPreConstraints(r *FieldRequest, hnd *ValueHandle) (bool, error)

func (CheckWhen) CheckListPostConstraints

func (y CheckWhen) CheckListPostConstraints(r ListRequest, child *Selection, key []val.Value) (bool, error)

type ChildRequest

type ChildRequest struct {
	Request
	From   *Selection
	New    bool
	Delete bool
	Meta   meta.HasDataDefinitions
}

func (*ChildRequest) IsNavigation

func (r *ChildRequest) IsNavigation() bool

type ConstraintHandler

type ConstraintHandler struct {
	NoFail      bool
	NewLocation string
	Violations  []error
}

func (*ConstraintHandler) ConstraintViolation

func (self *ConstraintHandler) ConstraintViolation(violation error) error

func (*ConstraintHandler) IncompleteResponse

func (self *ConstraintHandler) IncompleteResponse(location *Path)

func (*ConstraintHandler) LocatableNode

func (self *ConstraintHandler) LocatableNode(location *Path)

type Constraints

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

func NewConstraints

func NewConstraints(parent *Constraints) *Constraints

func (*Constraints) AddConstraint

func (self *Constraints) AddConstraint(id string, weight int, priority int, constraint interface{})

func (*Constraints) CheckActionPostConstraints

func (self *Constraints) CheckActionPostConstraints(r ActionRequest) (bool, error)

func (*Constraints) CheckActionPreConstraints

func (self *Constraints) CheckActionPreConstraints(r *ActionRequest) (bool, error)

func (*Constraints) CheckContainerPostConstraints

func (self *Constraints) CheckContainerPostConstraints(r ChildRequest, child *Selection) (bool, error)

func (*Constraints) CheckContainerPreConstraints

func (self *Constraints) CheckContainerPreConstraints(r *ChildRequest) (bool, error)

func (*Constraints) CheckFieldPostConstraints

func (self *Constraints) CheckFieldPostConstraints(r FieldRequest, hnd *ValueHandle) (bool, error)

func (*Constraints) CheckFieldPreConstraints

func (self *Constraints) CheckFieldPreConstraints(r *FieldRequest, hnd *ValueHandle) (bool, error)

func (*Constraints) CheckListPostConstraints

func (self *Constraints) CheckListPostConstraints(r ListRequest, child *Selection, key []val.Value) (bool, bool, error)

func (*Constraints) CheckListPreConstraints

func (self *Constraints) CheckListPreConstraints(r *ListRequest) (bool, error)

func (*Constraints) CheckNotifyFilterConstraints

func (self *Constraints) CheckNotifyFilterConstraints(msg *Selection) (bool, error)

func (*Constraints) Constraint

func (self *Constraints) Constraint(id string) interface{}

func (*Constraints) ContextConstraint

func (self *Constraints) ContextConstraint(s *Selection) context.Context

type ContainerPostConstraint

type ContainerPostConstraint interface {
	CheckContainerPostConstraints(r ChildRequest, child *Selection) (bool, error)
}

type ContainerPreConstraint

type ContainerPreConstraint interface {
	CheckContainerPreConstraints(r *ChildRequest) (bool, error)
}

type ContentConstraint

type ContentConstraint int
const (
	ContentAll ContentConstraint = iota
	ContentOperational
	ContentConfig
)

func NewContentConstraint

func NewContentConstraint(initialPath *Path, expression string) (c ContentConstraint, err error)

func (ContentConstraint) CheckContainerPreConstraints

func (self ContentConstraint) CheckContainerPreConstraints(r *ChildRequest) (bool, error)

func (ContentConstraint) CheckFieldPreConstraints

func (self ContentConstraint) CheckFieldPreConstraints(r *FieldRequest, hnd *ValueHandle) (bool, error)

type ContextConstraint

type ContextConstraint interface {
	ContextConstraint(*Selection) context.Context
}

type ErrorNode

type ErrorNode struct {
	Err error
}

Useful when you want to return an error from Data.Node(). Any call to get data will return same error

func (d *MyData) Node {
   return ErrorNode(errors.New("bang"))
}

func (ErrorNode) Action

func (e ErrorNode) Action(ActionRequest) (Node, error)

func (ErrorNode) BeginEdit

func (e ErrorNode) BeginEdit(r NodeRequest) error

func (ErrorNode) Child

func (e ErrorNode) Child(r ChildRequest) (Node, error)

func (ErrorNode) Choose

func (e ErrorNode) Choose(*Selection, *meta.Choice) (*meta.ChoiceCase, error)

func (ErrorNode) Context

func (ErrorNode) Context(s *Selection) context.Context

func (ErrorNode) Delete

func (e ErrorNode) Delete(r NodeRequest) error

func (ErrorNode) EndEdit

func (e ErrorNode) EndEdit(r NodeRequest) error

func (ErrorNode) Error

func (e ErrorNode) Error() string

func (ErrorNode) Field

func (ErrorNode) Next

func (e ErrorNode) Next(ListRequest) (Node, []val.Value, error)

func (ErrorNode) Notify

func (ErrorNode) Peek

func (e ErrorNode) Peek(sel *Selection, consumer interface{}) interface{}

func (ErrorNode) Release

func (ErrorNode) Release(s *Selection)

func (ErrorNode) String

func (e ErrorNode) String() string

type Event

type Event struct {
	Type EventType
	Src  Selection
}

func (Event) String

func (self Event) String() string

type EventType

type EventType int
const (
	EDIT EventType = iota + 1
	DELETE
)

func (EventType) String

func (e EventType) String() string

type FieldPostConstraint

type FieldPostConstraint interface {
	CheckFieldPostConstraints(r FieldRequest, hnd *ValueHandle) (bool, error)
}

type FieldPreConstraint

type FieldPreConstraint interface {
	CheckFieldPreConstraints(r *FieldRequest, hnd *ValueHandle) (bool, error)
}

type FieldRequest

type FieldRequest struct {
	Request
	Meta  meta.Leafable
	Write bool
	Clear bool
}

func (*FieldRequest) IsNavigation

func (r *FieldRequest) IsNavigation() bool

type FieldsMatcher

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

func NewExcludeFieldsMatcher

func NewExcludeFieldsMatcher(expression string) (fm *FieldsMatcher, err error)

NewExcludeFieldsMatcher excludes fields that match pattern

func NewFieldsMatcher

func NewFieldsMatcher(expression string) (fm *FieldsMatcher, err error)

func (*FieldsMatcher) CheckContainerPreConstraints

func (self *FieldsMatcher) CheckContainerPreConstraints(r *ChildRequest) (bool, error)

func (*FieldsMatcher) CheckFieldPreConstraints

func (self *FieldsMatcher) CheckFieldPreConstraints(r *FieldRequest, hnd *ValueHandle) (bool, error)

type Index

type Index struct {
	Keys []reflect.Value
	// contains filtered or unexported fields
}

Index help you implement Node.OnNext when you have a map to interate over

func NewIndex

func NewIndex(mmap interface{}) *Index

func (*Index) Len

func (self *Index) Len() int

func (*Index) Less

func (self *Index) Less(i, j int) bool

func (*Index) NextKey

func (self *Index) NextKey(row int) reflect.Value

func (*Index) Sort

func (self *Index) Sort(comparator func(a, b reflect.Value) bool)

func (*Index) Swap

func (self *Index) Swap(i, j int)

type KeyListBuilder

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

func NewKeyListBuilder

func NewKeyListBuilder(listPath string) *KeyListBuilder

func (*KeyListBuilder) List

func (klb *KeyListBuilder) List() []string

func (*KeyListBuilder) ParseKey

func (klb *KeyListBuilder) ParseKey(path string) bool

type ListItem

type ListItem struct {
	Selection *Selection
	Key       []val.Value
	// contains filtered or unexported fields
}

func (ListItem) Next

func (li ListItem) Next() (ListItem, error)

iterating a list, get next item in list

type ListPostConstraint

type ListPostConstraint interface {
	CheckListPostConstraints(r ListRequest, child *Selection, key []val.Value) (bool, bool, error)
}

type ListPreConstraint

type ListPreConstraint interface {
	CheckListPreConstraints(r *ListRequest) (bool, error)
}

type ListRange

type ListRange struct {
	Selector   PathMatcher
	CurrentRow int64
	StartRow   int64
	EndRow     int64
}

func NewListRange

func NewListRange(expression string) (lr *ListRange, err error)

func (*ListRange) CheckListPreConstraints

func (self *ListRange) CheckListPreConstraints(r *ListRequest) (bool, error)

type ListRequest

type ListRequest struct {
	Request
	From   *Selection
	New    bool
	Delete bool

	StartRow int

	// We make row available as a 32bit value for convenience but in theory
	// could be 64bit.  If you know you're list could not exceed 2 billion then
	// it's safe to use this value
	Row int

	StartRow64 int64
	Row64      int64
	First      bool
	Meta       *meta.List
	Key        []val.Value
}

func (*ListRequest) IncrementRow

func (r *ListRequest) IncrementRow()

func (*ListRequest) IsNavigation

func (r *ListRequest) IsNavigation() bool

func (*ListRequest) SetRow

func (r *ListRequest) SetRow(row int64)

func (*ListRequest) SetStartRow

func (r *ListRequest) SetStartRow(row int64)

type MaxDepth

type MaxDepth struct {
	MaxDepth int
}

func (MaxDepth) CheckContainerPreConstraints

func (md MaxDepth) CheckContainerPreConstraints(r *ChildRequest) (bool, error)

func (MaxDepth) CheckFieldPreConstraints

func (md MaxDepth) CheckFieldPreConstraints(r *FieldRequest, hnd *ValueHandle) (bool, error)

type MaxNode

type MaxNode struct {
	Count int
	Max   int
}

func (MaxNode) CheckContainerPreConstraints

func (self MaxNode) CheckContainerPreConstraints(r *ChildRequest) (bool, error)

type Node

type Node interface {

	// Child is called when navigating, creating or deleting a "container" or "list".
	// The request fields contain the nature of the request.
	//
	// Params:
	//  ChildRequest - contains the nature (e.g. get, delete, new) and details of the
	//                 request (e.g. identity name of the container or list )
	//
	// Return:
	//   Node - Return nil entity does not exist otherwise node implementation of the underlying
	//          node requested
	Child(r ChildRequest) (child Node, err error)

	// Next is called for items in a list when navigating, creating or deleting items in the
	// "list".
	//
	// Params:
	//  ListRequest - contains the nature (e.g. get, delete, new) and details of the
	//                 request (e.g. key, row number)
	//
	// Return:
	//   Node - Return nil entity does not exist otherwise node implementation of the underlying
	//          node requested
	//   []val.Value - If a key was defined in YANG, AND the request is for the next item
	//           in the list, then you must also return the key expressed in val.Value array
	Next(r ListRequest) (next Node, key []val.Value, err error)

	// Field is called to read or write "leaf" or "leaf-list" items on container/list items or
	// even root module.
	//
	// Params:
	//   FieldRequest - identity of the field and the contains the nature (e.g. read or write)
	//             tip: if the YANG defines the field as config:false, you can assume the field is
	//             only called for reading and you can ignore the flag for read v.s. write
	//
	//   *ValueHandle - contains a single the "Val" that with either:
	//                   a.) contain the value to be set or
	//                   b.) be expected to be set to the requested value to be read
	Field(r FieldRequest, hnd *ValueHandle) error

	// Choose is only called when there is a need to know which single case between several "choice/case"
	// sets are currently true.  This is only called when reading.
	//
	// Params:
	//   Selection - current selection that is handling the choice investigation
	//   *Choice - name for the choice (there could be several in a given container)
	//
	// Return:
	//   *ChoiceCase - which case is currently valid (there can be only one)
	//
	Choose(sel *Selection, choice *meta.Choice) (m *meta.ChoiceCase, err error)

	// BeginEdit is called simply to inform a node when it is about to be edited including deleting or creating.
	// While there is nothing required of nodes to do anything on this call, implementations might have
	// very important, internal operations they need to perform like obtaining write locks for example. It is
	// also an opportunity to reject the edit for whatever reason by returning an error.
	//
	// It important to know this is called on **every** parent node for any edit to any of their children.
	// This is known as "event bubbling" and can be helpful when parents are in a better position to handle
	// operations for children.  You can easily distinguish this situation from the NodeRequest parameter.
	// See https://github.com/freeconf/restconf/wiki/Edit-Node-Traversal for details on when this is called
	// in particular in the order
	//
	// Params:
	//  NodeRequest - contains the nature (e.g. get, delete, new)
	BeginEdit(r NodeRequest) error

	// EndEdit is called simply to inform a node after it has been edited including deleting or creating.
	// While there is nothing required of nodes to do anything on this call, implementations might have
	// very important, internal operations they need to perform like release write locks for example. It is
	// also an opportunity to apply changes to live application or persist data to permanent storage.
	//
	// It important to know this is called on **every** parent node for any edit to any of their children.
	// This is known as "event bubbling" and can be helpful when parents are in a better position to handle
	// operations for children.  You can easily distinguish this situation from the NodeRequest parameter.
	// See https://github.com/freeconf/restconf/wiki/Edit-Node-Traversal for details on when this is called
	// in particular in the order
	//
	// Params:
	//  NodeRequest - contains the nature (e.g. get, delete, new)
	EndEdit(r NodeRequest) error

	// Action(rpc/action) is called when caller wished to run a 'action' or 'rpc' definition.  Input can
	// be found in request if an input is defined.  Output only has to be returned for
	// definitions that declare an output.
	//
	// Params:
	//  ActionRequest - In addition to the identity name of the action or rpc, it may contains the "input"
	//        to the action if one was defined in the YANG.
	//
	// Return:
	//  Node - If there is an expected response from action ("output" defined in YANG) then this would be
	//        the Node implementation of that data.
	Action(r ActionRequest) (output Node, err error)

	// Notificationsare unique with respect to resources are allocated that survive the original
	// request so implementation should try not keep references to any more resources than neccessary
	// to ensure they do not reference objects that become stale or that impose large chunks of memory
	// unknowningly and unneccesarily.
	//
	// Params:
	//   NotifyRequest - In addition to the identity name of the notification, this contains the stream
	//        to write events to.
	//
	// Return:
	//   NotifyCloser - Function to called to stop streaming events. This will be called for example when
	//      client closes the event stream socket either naturally or because of a network disconnect.
	//
	Notify(r NotifyRequest) (NotifyCloser, error)

	// Peek give an opportunity for API callers to gain access to the objects behind a node.
	//
	// Params:
	//   Selection - current selection that is handling the peeking
	//   interface{} - Who (or under what context) is attempting to peek. This can be used by
	//         node implementation to decide what is returned or if anything at all is returned.
	//         It may also be ingored.  This is up to
	//
	// Return:
	//   interface{} - Can be anything.
	//
	// This can be considered a violation of abstraction so implementation is not gauranteed and
	// can vary w/o any compiler warnings.  This can be useful in unit testing but uses outside this
	// should be used judicously.
	Peek(sel *Selection, consumer interface{}) interface{}

	// Context provides an opportunity to add/change values in the request context that is passed to
	// operations on this node and operations to children of this node.  FreeCONF does not put or
	// require anything in the context, it is meant as a way to make application or request specific
	// data available to nodes.
	//
	// A popular use of context is to store the user and or user roles making the request so
	// operations can authorize or log user operations.  See RESTCONF request filters for one
	// way to implement that.
	//
	// In addition, if you want to obtain a read-lock on your object that will be released in
	// Release when there are no more references to you object, this would be where to do that
	Context(sel *Selection) context.Context

	// Underlying object is no longer being references. Release read-lock if you obtained one
	// in call to Context
	Release(sel *Selection)
}

Node is at the root of where your application's data management and functionality is contained and made available.

When building your application management logic, you will register a single instance of a node representing the root of the module that will lead to all of nodes, functions and event streams. Each of these nodes, functions and event streams will align with the definitions in the YANG file.

You can use data structures nodeutil.Basic, nodeutil.Extend or nodeutil.Reflect that implement this interface to reduce the amount of required coding.

The root Node together with the meta.Module represent the top most node and can be obtained using node.Browser's Root() function to return a node.Selection data structure that links the Node and the Module. This root Selection then be used to navigate you manament application thru a series of nested Selections of meta.Meta and node.Node pairings. See https://freeconf.org/docs/reference/basic-components/ for how Node works with other objects

Node are constructed as needed so two separate requests to the same management function would have different Node instances. This means you can keep temporary state like lazy list indexes or references to request specific data in your node implementation. The only time a Node is not garage collected after a request is finished is if it is Root node or there is an active event stream via a Notification subscription.

type NodeRequest

type NodeRequest struct {
	Selection *Selection
	New       bool
	Delete    bool
	Source    *Selection
	EditRoot  bool
}

type Notification

type Notification struct {
	EventTime time.Time
	Event     *Selection
}

func NewNotification

func NewNotification(msg *Selection) Notification

func NewNotificationWhen

func NewNotificationWhen(msg *Selection, t time.Time) Notification

type NotifyCloser

type NotifyCloser func() error

NotifyCloser callback when caller is not interested in events anymore. Typically this is where you remove listeners

type NotifyFilterConstraint

type NotifyFilterConstraint interface {
	CheckNotifyFilterConstraints(msg *Selection) (bool, error)
}

func NewFilterConstraint

func NewFilterConstraint(filter string) (NotifyFilterConstraint, error)

type NotifyRequest

type NotifyRequest struct {
	Request
	Meta   *meta.Notification
	Stream NotifyStream
}

func (NotifyRequest) Send

func (r NotifyRequest) Send(n Node)

func (NotifyRequest) SendWhen

func (r NotifyRequest) SendWhen(n Node, t time.Time)

type NotifyStream

type NotifyStream func(n Notification)

NotifyStream is pipe back to subscriber.

type Path

type Path struct {
	Meta   meta.Definition
	Key    []val.Value
	Parent *Path
}

Path in data tree (not meta) resembling a RESTCONF URL when printed to a string

func (*Path) Equal

func (a *Path) Equal(b *Path) bool

func (*Path) EqualNoKey

func (a *Path) EqualNoKey(b *Path) bool

func (*Path) Len

func (path *Path) Len() (len int)

func (*Path) Segments

func (path *Path) Segments() []*Path

func (*Path) String

func (seg *Path) String() string

func (*Path) StringNoModule

func (seg *Path) StringNoModule() string

type PathMatchExpression

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

func ParsePathExpression

func ParsePathExpression(selector string) (*PathMatchExpression, error)

func (*PathMatchExpression) PathMatches

func (self *PathMatchExpression) PathMatches(base *Path, candidate *Path) bool

func (*PathMatchExpression) String

func (self *PathMatchExpression) String() string

type PathMatcher

type PathMatcher interface {
	PathMatches(base *Path, tail *Path) bool
}

type PathSlice

type PathSlice struct {
	Head *Path
	Tail *Path
}

func NewPathSlice

func NewPathSlice(path string, m meta.HasDefinitions) (p PathSlice)

func ParsePath

func ParsePath(path string, m meta.HasDefinitions) (PathSlice, error)

func ParseUrlPath

func ParseUrlPath(u *url.URL, m meta.Definition) (PathSlice, error)

func (PathSlice) Empty

func (self PathSlice) Empty() bool

func (PathSlice) Len

func (self PathSlice) Len() (len int)

func (PathSlice) Segments

func (self PathSlice) Segments() []*Path

func (PathSlice) String

func (self PathSlice) String() string

type Request

type Request struct {
	Selection *Selection

	// Path to meta item requested, including leaf requests
	Path *Path

	Target *Path
	Base   *Path
}

Request is base class for all other node requests. There are two basic modes: 1. Navigation where NavTarget is set and 2.)Editing where WalkBase is set

type Selection

type Selection struct {

	// Browser that this selection ultimately spawned from
	Browser *Browser

	// Underlying node that implements management functions
	Node Node

	// Meta path in YANG module tied to this node
	Path *Path

	// Potentialy stores external data made available to all requests
	Context context.Context

	// Useful when navigating lists, True if this selector is List node, False if
	// this is for an item in List node.
	InsideList bool

	// Constraints hold list of things to check when walking or editing a node.
	Constraints *Constraints
	// contains filtered or unexported fields
}

Selection give you access to all management operations on an manamagent API. It combines a single data node (node.Node) with a single model definition (meta.Meta) to represent a single location on a management API (including the root location).

From here you can perform many operations from the underlying nodes including the following:

  1. Find/navigate to any other point in the management API
  2. Get data (i.e. export)
  3. Write data (i.e perform an edit)
  4. Run an Action/RPC
  5. Subscribe to an event stream
  6. Delete data

You can chan

 Example:
    var err error
    root := browser.Root()
    jay := root.Find("birds=bluejay")
    myCheckErr(dim.LastErr)

    // write
    err = jay.UpsertFrom(nodeutil.ReadJSON(`{"dimensions":55}`)).LastErr

    // read
    err = jay.UpsertInto(someOtherNode)

    // action
    _, err = jay.Find("fly").Action(nil)

    // subscribe
    reportRareBird := func(msg node.Selection) {
	        fmt.Println(nodeutil.ReadJSON(msg))
    }
    unsubscribe, err := root.Find("rareSighting").Notify(reportRareBird)
    // unsubscribe
    unsubscribe()

func (*Selection) Action

func (sel *Selection) Action(input Node) (*Selection, error)

Action let's to call a procedure potentially passing on data and potentially recieving data back.

func (*Selection) ClearField

func (sel *Selection) ClearField(m meta.Leafable) error

ClearField write nil/empty value to field.

func (*Selection) Constrain

func (sel *Selection) Constrain(params string) (*Selection, error)

Apply constraints in the form of url parameters. Original selector and constraints will remain unaltered Example:

   sel2 = sel.Constrain("content=config&depth=4")
sel will not have content or depth constraints applies, but sel 2 will

func (*Selection) Delete

func (sel *Selection) Delete() (err error)

func (*Selection) Find

func (sel *Selection) Find(path string) (*Selection, error)

Find navigates to another selector automatically applying constraints to returned selector. This supports paths that start with any number of "../" where FindUrl does not.

func (*Selection) FindUrl

func (sel *Selection) FindUrl(url *url.URL) (*Selection, error)

FindUrl navigates to another selection with possible constraints as url parameters. Constraints are added to any existing contraints. Original selector and constraints will remain unaltered

func (*Selection) First

func (sel *Selection) First() (ListItem, error)

If at list, this will be iterator into first item in list

func (*Selection) Get

func (sel *Selection) Get() (val.Value, error)

GetValue let's you get the leaf value as a Value instance. Returns null if value is null

func (*Selection) InsertFrom

func (sel *Selection) InsertFrom(fromNode Node) error

InsertFrom Copy given node into current node. If there are any existing containers of list items then this will fail by design.

func (*Selection) InsertInto

func (sel *Selection) InsertInto(toNode Node) error

InsertInto Copy current node into given node. If there are any existing containers of list items then this will fail by design.

func (*Selection) Key

func (sel *Selection) Key() []val.Value

If this is a selection in a list, this is the key value of that list item.

func (*Selection) Meta

func (sel *Selection) Meta() meta.Definition

func (*Selection) Notifications

func (sel *Selection) Notifications(stream NotifyStream) (NotifyCloser, error)

Notifications let's caller subscribe to a node. Node must be a 'notification' node.

func (*Selection) Peek

func (sel *Selection) Peek(consumer interface{}) interface{}

func (*Selection) Release

func (sel *Selection) Release()

func (*Selection) ReplaceFrom

func (sel *Selection) ReplaceFrom(fromNode Node) error

func (*Selection) Set

func (sel *Selection) Set(v val.Value) error

When you've selected a leaf field, this will set the value. Value must be in correct type according to YANG

func (*Selection) SetValue

func (sel *Selection) SetValue(value interface{}) error

When you've selected a leaf field, this will coerse the data into correct value type then set. Error if coersion is not successful

func (*Selection) Split

func (sel *Selection) Split(node Node) *Selection

Create a new independant selection with a different browser from this point in the tree based on a whole new data node

func (*Selection) UpdateFrom

func (sel *Selection) UpdateFrom(fromNode Node) error

Copy given node into current node. There must be matching containers of list items or this will fail by design.

func (*Selection) UpdateInto

func (sel *Selection) UpdateInto(toNode Node) error

Copy current node into given node. There must be matching containers of list items or this will fail by design.

func (*Selection) UpsertFrom

func (sel *Selection) UpsertFrom(fromNode Node) error

Merge given node into current node. If there are any existing containers of list items then data will be merged.

func (*Selection) UpsertFromSetDefaults

func (sel *Selection) UpsertFromSetDefaults(fromNode Node) error

UpsertFromSetDefauls is like UpsertFrom but top container will have defaults set from YANG

func (*Selection) UpsertInto

func (sel *Selection) UpsertInto(toNode Node) error

UpsertInto Merge current node into given node. If there are any existing containers of list items then data will be merged.

func (*Selection) UpsertIntoSetDefaults

func (sel *Selection) UpsertIntoSetDefaults(toNode Node) error

UpsertIntoSetDefaults is like UpsertInto but top container will have defaults set from YANG

func (*Selection) XFind

func (sel *Selection) XFind(path xpath.Path) (*Selection, error)

func (*Selection) XPredicate

func (sel *Selection) XPredicate(p xpath.Path) (bool, error)

type Trigger

type Trigger struct {

	// OnBegin will be called on the start of any edit. Return error to stop edit
	OnBegin TriggerFunc

	// OnEnd will be called at the end of any edit. Return error to mark edit as failed
	OnEnd TriggerFunc
	// contains filtered or unexported fields
}

Trigger for registering global listeners on a data model. Useful for triggering on save or push notifications

type TriggerFunc

type TriggerFunc func(t *Trigger, r NodeRequest) error

TriggerFunc callback for triggers

type TriggerTable

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

TriggerTable is registry of all trigger functions for a browser

func NewTriggerTable

func NewTriggerTable() *TriggerTable

NewTriggerTable creates new registry of all trigger functions for a browser

func (*TriggerTable) Install

func (self *TriggerTable) Install(t *Trigger)

Install will register new trigger functions

func (*TriggerTable) Remove

func (self *TriggerTable) Remove(t *Trigger)

Remove will no longer call trigger funcs

type ValueHandle

type ValueHandle struct {

	// Readers do not set this, Writers will always have a valid value here
	Val val.Value
}

Used to pass values in/out of calls to Node.Field

type Where

type Where struct {
	Filter string // XPath filter
	// contains filtered or unexported fields
}

func NewWhere

func NewWhere(filter string) (*Where, error)

func (*Where) CheckListPostConstraints

func (w *Where) CheckListPostConstraints(r ListRequest, child *Selection, key []val.Value) (bool, bool, error)

type WithDefaults

type WithDefaults int

Field level filter that let's you see the differences in values from the default values.

For more information, see:

https://tools.ietf.org/html/draft-ietf-netconf-restconf-16#section-4.8.9
const (
	// Show all values, default and otherwise.  This is really the same as not specifying
	// any constraint
	WithDefaultsAll WithDefaults = iota

	// Hide values that match the default whether the user has explicitly set or not
	WithDefaultsTrim

	// See https://tools.ietf.org/html/rfc6243#section-3.3
	// This is really about returning the values the "happen" to match the default. Not all
	// implementations will be able to distinguish this.
	// Example:  if leaf x has a default of 5 and user never sets the value to 5, then using
	// this default will NOT return a value for x.  If however the user set the value to exactly
	// and explicitly to 5, then using this paramaeter WILL return a value for x as 5.
	//
	// While a very useful flag, this not supported yet only because there are no data node
	// implementations that support this yet. In addition, user interfaces would have to allow the user
	// to "clear" a value to assume the default v.s. setting a value to the default to pin the value to
	// that value in case the model default value changes.
	WithDefaultsExplicit

	// Not supported
	// See https://tools.ietf.org/html/rfc6243#section-3.4
	// This mangles the JSON output so instead of
	//   "x" : 10
	//  you have soemthing like this
	//   "x" : 10,
	//   "ietf-netconf-with-defaults" : {
	//       "x" : 5
	//   }
	//  although i'm not 100% positive, either way, this is not supported yet
	WithDefaultsAllTagged
)

func NewWithDefaultsConstraint

func NewWithDefaultsConstraint(expression string) (WithDefaults, error)

func (WithDefaults) CheckFieldPostConstraints

func (self WithDefaults) CheckFieldPostConstraints(r FieldRequest, hnd *ValueHandle) (bool, error)

Jump to

Keyboard shortcuts

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