yamlutil

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func YAMLDocumentsToJSON

func YAMLDocumentsToJSON(yamlStream io.Reader) iter.Seq[YAMLToJSON]

YAMLDocumentsToJSON converts a stream of YAML documents into a sequence of JSON documents.

Example
package main

import (
	"bytes"
	_ "embed"
	"fmt"

	"github.com/Izzette/kubectl-api-resource-versions/internal/yamlutil"
)

//go:embed testdata/documents.yaml
var document string

func main() {
	buf := bytes.NewBufferString(document)
	for result := range yamlutil.YAMLDocumentsToJSON(buf) {
		decoder, err := result.GetDecoder()
		if err != nil {
			panic(err)
		}

		var jsonDoc any
		if err := decoder.Decode(&jsonDoc); err != nil {
			panic(err)
		}

		fmt.Printf("%#v\n", jsonDoc)
	}
}
Output:

[]interface {}{map[string]interface {}{"key":"value"}, map[string]interface {}{"key2":"value2"}, map[string]interface {}{"key3":"value3"}}
map[string]interface {}{"other":"value", "with":map[string]interface {}{"different":"structure"}}
<nil>

Types

type YAMLToJSON

type YAMLToJSON interface {
	// GetDecoder returns a JSON decoder for the document, or an error if the document could not be transcoded to JSON.
	GetDecoder() (*json.Decoder, error)
}

YAMLToJSON provides either the transcoded document, or an error if an error occurred during the transcoding process.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL