Skip to content

iterating over YAML!

License

Notifications You must be signed in to change notification settings

dprotaso/go-yit

Repository files navigation

go-yit - YAML Iterator

GoDoc

Introduction

This library compliments go-yaml v3 by adding functional style methods for iterating over YAML documents.

Usage

Import the package

import "github.com/dprotaso/go-yit"

Query your YAML document

package main

import (
	"fmt"
	"log"

	"github.com/dprotaso/go-yit"
	"gopkg.in/yaml.v3"
)

var data = `
a: b
c: d
e: f
`

func main() {
	var doc yaml.Node
	err := yaml.Unmarshal([]byte(data), &doc)

	if err != nil {
		log.Fatalf("error: %v", err)
	}

	it := yit.FromNode(&doc).
		RecurseNodes().
		Filter(yit.WithKind(yaml.MappingNode)).
		MapKeys()

	for node, ok := it(); ok; node, ok = it() {
		fmt.Println(node.Value)
	}
}

About

iterating over YAML!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages