Documentation ¶
Overview ¶
Example (SubstationCustomConfig) ¶
// Substation applications rely on a context for cancellation and timeouts. ctx := context.Background() // Define and load the custom configuration. This config includes a username // and password for authentication. conf := []byte(` { "transforms":[ {"type":"object_copy","settings":{"object":{"source_key":"a","target_key":"c"}}}, {"type":"send_stdout"} ], "auth":{ "username":"foo", "password":"bar" } } `) cfg := customConfig{} if err := json.Unmarshal(conf, &cfg); err != nil { // Handle error. panic(err) } // Create a new Substation instance from the embedded configuration. sub, err := substation.New(ctx, cfg.Config) if err != nil { // Handle error. panic(err) } // Print the Substation configuration. fmt.Println(sub) // Print the custom configuration. fmt.Println(cfg)
Output: {"transforms":[{"type":"object_copy","settings":{"object":{"source_key":"a","target_key":"c"}}},{"type":"send_stdout","settings":null}]} foo:bar
Example (SubstationCustomTransforms) ¶
// Substation applications rely on a context for cancellation and timeouts. ctx := context.Background() // Define and load the configuration. This config includes a transform that // is not part of the standard Substation package. conf := []byte(` { "transforms":[ {"type":"utility_duplicate"}, {"type":"send_stdout"} ] } `) cfg := substation.Config{} if err := json.Unmarshal(conf, &cfg); err != nil { // Handle error. panic(err) } // Create a new Substation instance with a custom transform factory for loading // the custom transform. sub, err := substation.New(ctx, cfg, substation.WithTransformFactory(customFactory)) if err != nil { // Handle error. panic(err) } msg := []*message.Message{ message.New().SetData([]byte(`{"a":"b"}`)), message.New().AsControl(), } // Transform the group of messages. In this example, results are not used. if _, err := sub.Transform(ctx, msg...); err != nil { // Handle error. panic(err) }
Output: {"a":"b"} {"a":"b"}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Library string
Functions ¶
func WithTransformFactory ¶
func WithTransformFactory(fac transform.Factory) func(*Substation)
WithTransformFactory implements a custom transform factory.
Types ¶
type Config ¶
type Config struct { // Transforms contains a list of data transformatons that are executed. Transforms []config.Config `json:"transforms"` }
Config is the core configuration for the application. Custom applications should embed this and add additional configuration options.
type Substation ¶
type Substation struct {
// contains filtered or unexported fields
}
Substation provides access to data transformation functions.
Example ¶
// Substation applications rely on a context for cancellation and timeouts. ctx := context.Background() // Define a configuration. For native Substation applications, this is managed by Jsonnet. // // This example copies an object's value and prints the data to stdout. conf := []byte(` { "transforms":[ {"type":"object_copy","settings":{"object":{"source_key":"a","target_key":"c"}}}, {"type":"send_stdout"} ] } `) cfg := substation.Config{} if err := json.Unmarshal(conf, &cfg); err != nil { // Handle error. panic(err) } // Create a new Substation instance. sub, err := substation.New(ctx, cfg) if err != nil { // Handle error. panic(err) } // Print the Substation configuration. fmt.Println(sub) // Substation instances process data defined as a Message. Messages can be processed // individually or in groups. This example processes multiple messages as a group. msg := []*message.Message{ // The first message is a data message. Only data messages are transformed. message.New().SetData([]byte(`{"a":"b"}`)), // The second message is a ctrl message. ctrl messages flush the pipeline. message.New().AsControl(), } // Transform the group of messages. In this example, results are not used. if _, err := sub.Transform(ctx, msg...); err != nil { // Handle error. panic(err) }
Output: {"transforms":[{"type":"object_copy","settings":{"object":{"source_key":"a","target_key":"c"}}},{"type":"send_stdout","settings":null}]} {"a":"b","c":"b"}
func New ¶
func New(ctx context.Context, cfg Config, opts ...func(*Substation)) (*Substation, error)
New returns a new Substation instance.
func (*Substation) String ¶
func (s *Substation) String() string
String returns a JSON representation of the configuration.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package config provides structures for building configurations.
|
Package config provides structures for building configurations. |
internal
|
|
config
package config provides configuration types and functions for Substation.
|
package config provides configuration types and functions for Substation. |
file
package file provides functions that can be used to retrieve files from local and remote locations.
|
package file provides functions that can be used to retrieve files from local and remote locations. |
log
Package log wraps logrus and provides global logging only debug logging should be used in condition/, process/, and internal/ to reduce the likelihood of corrupting output for apps debug and info logging can be used in cmd/
|
Package log wraps logrus and provides global logging only debug logging should be used in condition/, process/, and internal/ to reduce the likelihood of corrupting output for apps debug and info logging can be used in cmd/ |
media
package media provides capabilities for inspecting the content of data and identifying its media (Multipurpose Internet Mail Extensions, MIME) type.
|
package media provides capabilities for inspecting the content of data and identifying its media (Multipurpose Internet Mail Extensions, MIME) type. |
secrets
Package secrets provides functions for retrieving local and remote secrets and interpolating them into configuration files.
|
Package secrets provides functions for retrieving local and remote secrets and interpolating them into configuration files. |
Package message provides functions for managing data used by conditions and transforms.
|
Package message provides functions for managing data used by conditions and transforms. |
Package transform provides functions for transforming messages.
|
Package transform provides functions for transforming messages. |
Click to show internal directories.
Click to hide internal directories.