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.
Click to show internal directories.
Click to hide internal directories.