Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSeriesValue

func AddSeriesValue(c *Component, key, value interface{})

    AddSeriesValue is a helper which adds a value to a series which is being stored under the given key on the given Component. The series of values added under any key can be retrieved with GetSeriesValues.

    Additionally, AddSeriesValue keeps track of the order of calls to itself and children spawned from the Component. By using GetSeriesElements you can retrieve the sequence of values and children in the order they were added to the Component.

    func BreadthFirstVisit

    func BreadthFirstVisit(c *Component, callback func(*Component) bool)

      BreadthFirstVisit visits this Component and all of its children, and their children, etc... in a breadth-first order. If the callback returns false then the function returns without visiting any more Components.

      func InheritedValue

      func InheritedValue(c *Component, key interface{}) (interface{}, bool)

        InheritedValue returns the value which has been set for the given key. It first looks for the key on the receiver Component. If not found, it will look on its parent Component, and so on, until the key is found. If the key is not found on any Components, up to the root Component, then false is returned.

        func SeriesValues

        func SeriesValues(c *Component, key interface{}) []interface{}

          SeriesValues returns the sequence of values that have been added to the Component under the given key via AddSeriesValue, in the same order the values were added.

          Types

          type Component

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

            Component describes a single component of a program, and holds onto key/values for that component for use in generic libraries which instantiate those components.

            When instantiating a component it's generally necessary to know where in the component hierarchy it lies, for purposes of creating configuration parameters and so-forth. To support this, Components are able to spawn of child Components, each with a blank key/value namespace. Each child is differentiated from the other by a name, and a Component is able to use its Path (the sequence of names of its ancestors) to differentiate itself from any other component in the hierarchy.

            A new Component, i.e. the root Component in the hierarchy, can be initialized by doing:

            new(Component).
            

            Method's on Component are thread-safe.

            func (*Component) Annotate

            func (c *Component) Annotate(kv ...interface{})

              Annotate annotates the Component's internal Context in-place, such that they will be included in any future calls to the Context method.

              func (*Component) Child

              func (c *Component) Child(name string) *Component

                Child returns a new child component of the method receiver. The child will have the given name, and its Path will be the receiver's path with the name appended. The child will not inherit any of the receiver's key/value pairs.

                If a child of the given name has already been created this method will panic.

                func (*Component) Children

                func (c *Component) Children() []*Component

                  Children returns all Components created via the Child method on this Component, in the order they were created.

                  func (*Component) Context

                  func (c *Component) Context() context.Context

                    Context returns a Context which has been annotated with any annotations from Annotate calls to this Component, as well as some default annotations which are always included.

                    func (*Component) HasValue

                    func (c *Component) HasValue(key interface{}) bool

                      HasValue returns true if the given key has had a value set on it with SetValue.

                      func (*Component) Name

                      func (c *Component) Name() (string, bool)

                        Name returns the name this Component was created with (via the Child method), or false if this Component was not created via Child (and is therefore the root Component).

                        func (*Component) Parent

                        func (c *Component) Parent() *Component

                          Parent returns the Component from which this one was created via the Child method. This returns nil if this Component was not created via Child (and is therefore the root Component).

                          func (*Component) Path

                          func (c *Component) Path() []string

                            Path returns the sequence of names which were passed into Child calls in order to create this Component. If the Component was not created via Child (and is therefore the root Component) this will return an empty slice.

                            root := new(Component)
                            child := root.Child("child")
                            grandChild := child.Child("grandchild")
                            fmt.Printf("%#v\n", root.Path())     	// "[]string(nil)"
                            fmt.Printf("%#v\n", child.Path())       // []string{"child"}
                            fmt.Printf("%#v\n", grandChild.Path())  // []string{"child", "grandchild"}
                            

                            func (*Component) SetValue

                            func (c *Component) SetValue(key, value interface{})

                              SetValue sets the given key to the given value on the Component, overwriting any previous value for that key.

                              func (*Component) Value

                              func (c *Component) Value(key interface{}) interface{}

                                Value returns the value which has been set for the given key.

                                func (*Component) Values

                                func (c *Component) Values() map[interface{}]interface{}

                                  Values returns all key/value pairs which have been set via SetValue.

                                  type SeriesElement

                                  type SeriesElement struct {
                                  	Child *Component
                                  	Value interface{}
                                  }

                                    SeriesElement is used to describe a single element in a series, as implemented by AddSeriesValue. A SeriesElement can either be a Child which was spawned from the Component, or a Value which was added via AddSeriesValue.

                                    func SeriesElements

                                    func SeriesElements(c *Component, key interface{}) []SeriesElement

                                      SeriesElements returns the sequence of values that have been added to the Component under the given key via AddSeriesValue, interlaced with children which have been spawned from the Component, in the same respective order the events originally happened.

                                      func SeriesGetElement

                                      func SeriesGetElement(c *Component, key interface{}, i int) (SeriesElement, bool)

                                        SeriesGetElement returns the ith element in the series at the given key.