Documentation
¶
Index ¶
- func Decode(input, output interface{}) error
- type Capsule
- func (c *Capsule) Data() []byte
- func (c *Capsule) Delete(key string) (err error)
- func (c *Capsule) Get(key string) json.Result
- func (c *Capsule) Metadata() []byte
- func (c *Capsule) Set(key string, value interface{}) (err error)
- func (c *Capsule) SetData(b []byte) *Capsule
- func (c *Capsule) SetMetadata(i interface{}) (*Capsule, error)
- func (c *Capsule) SetRaw(key string, value interface{}) (err error)
- type Channel
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Capsule ¶
type Capsule struct {
// contains filtered or unexported fields
}
Capsule stores encapsulated data that is used throughout the package's data handling and processing functions.
Each capsule contains two unexported fields that are accessed by getters and setters:
- data: stores structured or unstructured data
- metadata: stores structured metadata that describes the data
Values in the metadata field are accessed using the pattern "!metadata [key]". JSON values can be freely moved between the data and metadata fields.
Capsules can be created and initialized using this pattern, where b is a []byte and v is an interface{}:
capsule := NewCapsule() capsule.SetData(b).SetMetadata(v)
Substation applications follow these rules when handling capsules:
- Sources set the initial metadata, but this can be modified in transit by applying processors
- Sinks only output data, but metadata can be retained by copying it from metadata into data
func (*Capsule) Delete ¶
Delete removes a key from a JSON object stored in the capsule's data or metadata fields.
func (*Capsule) Get ¶
Get retrieves a value from a JSON object stored in the capsule's data or metadata fields.
func (*Capsule) Metadata ¶ added in v0.5.0
Metadata returns the contents of the capsule's metadata field.
func (*Capsule) Set ¶
Set writes a value to a JSON object stored in the capsule's data or metadata fields.
func (*Capsule) SetMetadata ¶
SetMetadata writes data to the capsule's metadata field. Metadata must be an interface that can marshal to a JSON object.
type Channel ¶ added in v0.5.0
type Channel struct {
C chan Capsule
// contains filtered or unexported fields
}
Channel provides methods for safely writing capsule data to and closing channels. Data should be read directly from the channel (e.g., ch.C).
func NewChannel ¶ added in v0.5.0
func NewChannel() *Channel
NewChannel returns an unbuffered channel.
func (*Channel) Close ¶ added in v0.5.0
func (c *Channel) Close()
Close closes a channel and relies on a mutex to prevent panicking if the channel is closed by multiple goroutines.
func (*Channel) Send ¶ added in v0.5.0
Send writes capsule data to a channel and relies on goroutine recovery to prevent panicking if writes are attempted on a closed channel. Read more about recovery here: https://go.dev/blog/defer-panic-and-recover.