Golang YAML node pipeline.
This is currently alpha, with some features still in development, and not full test coverage. We're on it! 💪
This program does the following:
- Creates a pipeline input that just provides a YAML from a constant
- More realistic examples would pipe YAML from a file or a stream
- Creates a pipeline of two steps:
- Accepts only nodes whose
include
property equalstrue
- Sends those nodes to a node channel
- Accepts only nodes whose
- Pipes nodes sent to the node channel into
stderr
package main
import (
"context"
. "github.com/arikkfir/gstream/pkg"
. "github.com/arikkfir/gstream/pkg/generate"
. "github.com/arikkfir/gstream/pkg/processing"
. "github.com/arikkfir/gstream/pkg/sink"
. "github.com/arikkfir/gstream/pkg/types"
"gopkg.in/yaml.v3"
"os"
"strings"
)
const yml = `
key: value1
include: true
---
key: value2
include: false
---
key: value3
include: true`
func main() {
s := NewStream().
Generate(FromReader(strings.NewReader(yml))).
Transform(YAMLPathFilter("$[?(@.include==true)]")).
Sink(ToWriter(os.Stdout))
if err := s.Execute(context.Background()); err != nil {
panic(err)
}
}
This will print the following:
key: value1
include: true
---
key: value3
include: true