Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • 0.8.2
  • 0.8.1
  • 0.8.0
  • 0.7.13
  • 0.7.12
  • 0.7.11
  • 0.7.10
  • 0.7.9
  • 0.7.8
  • 0.7.7
  • 0.7.6
  • 0.7.5
  • 0.7.4
  • 0.7.3
  • 0.7.2
  • 0.7.1
  • 0.7.0
  • 0.6.27
  • 0.6.26
  • 0.6.25
21 results

README.md

Blame
  • 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)
    	}
    }