Skip to content

arikkfir/gstream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gstream

Maintainer GoVersion GoDoc GoReportCard codecov

Golang YAML node pipeline.

Status

This is currently alpha, with some features still in development, and not full test coverage. We're on it! 💪

Example

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 equals true
    • Sends those nodes to a node channel
  • 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

Sponsor this project

Packages

No packages published

Languages