caching/vendor/sigs.k8s.io/yaml
Knative Automation b3781bc47a
upgrade to latest dependencies (#806)
bumping knative.dev/pkg b7a62c0...35011d4:
  > 35011d4 upgrade to latest dependencies (# 2892)
  > 5c9b7a8 upgrade to latest dependencies (# 2887)
  > acf0a2d Bump google.golang.org/api from 0.148.0 to 0.149.0 (# 2891)
  > 5e1261a Bump cloud.google.com/go/storage from 1.33.0 to 1.34.1 (# 2890)
  > 3b3f4e4 Bump github.com/gorilla/websocket from 1.5.0 to 1.5.1 (# 2889)
  > 8bf0f54 Bump golang.org/x/sync from 0.4.0 to 0.5.0 (# 2888)
  > fac3a4f fix closure variable in filtered factory (# 2884)
  > a6c730f upgrade to latest dependencies (# 2882)
  > b09d4f2 Bump sigs.k8s.io/yaml from 1.3.0 to 1.4.0 (# 2879)
  > 9f71af7 Bump github.com/google/uuid from 1.3.1 to 1.4.0 (# 2878)
bumping google.golang.org/genproto d307bd8...49dd2c1:
  > 49dd2c1 chore(all): update all (# 1067)
  > e917dd1 chore(deps): bump golang.org/x/net in /googleapis/api/servicecontrol (# 1063)
  > 8102cb6 chore(deps): bump golang.org/x/net in /googleapis/api/servicemanagement (# 1060)
  > baa7128 chore(deps): bump golang.org/x/net in /googleapis/api/apikeys (# 1062)
  > 67c69aa chore(deps): bump golang.org/x/net in /googleapis/bytestream (# 1061)
  > e298162 chore(deps): bump golang.org/x/net in /googleapis/api/serviceusage (# 1064)
  > 378ed82 chore(deps): bump golang.org/x/net in /googleapis/api (# 1065)
  > a6244dc chore(deps): bump golang.org/x/net from 0.14.0 to 0.17.0 (# 1066)
  > 8bfb1ae chore(all): update all (# 1059)
  > ceb4ed7 chore(all): auto-regenerate .pb.go files (# 1058)
bumping github.com/google/uuid b3cae7c...8de8764:
  > 8de8764 chore(master): release 1.4.0 (# 134)
  > 7c22e97 Clarify the documentation of Parse to state its job is to parse, not validate, strings. (# 135)
  > cd5fbbd feat: UUIDs slice type with Strings() convenience method (# 133)
  > 47f5b39 docs: fix a typo in CONTRIBUTING.md (# 130)
  > 542ddab chore(tests): add Fuzz tests (# 128)
  > 06716f6 chore(tests): Add json.Unmarshal test with empty value cases (# 116)
bumping knative.dev/hack d4af42e...8834794:
  > 8834794 Call set_latest_to_highest_semver after publishing a new release (# 343)
  > 0d99b7e add function to set latest semver to latest (# 339)
bumping sigs.k8s.io/yaml 9535b3b...c3772b5:
  > c3772b5 Merge pull request # 97 from liggitt/owners
  > eead467 Merge pull request # 76 from natasha41575/go-yaml-fork
  > 604031b Update owners
  > 3566774 Merge pull request # 96 from liggitt/msg
  > f2c0229 add test demonstrating consistency between yaml.v2 and yaml.v3
  > 65d71bb Merge pull request # 87 from justinsb/spew_no_more
  > 3f79f32 Revert error message changes
  > 20d25fa update LICENSE, owners, and readmes
  > d865f09 Merge pull request # 83 from kubernetes-sigs/bump-version-of-golang-to-1.19-and-drop-older-versions
  > 13f0a74 Replace go-spew with go-cmp
  > a7b5665 exclude forked libs from golint
  > 5303805 Merge pull request # 75 from brianpursley/benchmarks
  > b02c352 reformat to golang 1.19 standards
  > b6d8b45 fix leading newline issue
  > b5bdf49 Merge pull request # 66 from ncdc/remove-ncdc-from-owners
  > 0beda2b Add benchmarks
  > 2f8489c Bump version of golang to 1.19 and prune older versions
  > 330e1e5 make sequence style configurable
  > 78c1299 Merge pull request # 69 from ncdc/fix-lint-error
  > 94f1bbd Remove myself (ncdc) from OWNERS
  > 2d151d8 Add benchmarks
  > 70ebea7 change import paths to forked yaml libs
  > 39f74b9 Merge pull request # 65 from amurant/non_functional
  > 5e30182 Fix lint error
  > b96582b fork go-yaml v2 and v3
  > 4f103b1 greatly improve testing framework & added a lot of new tests
  > 3c98e65 expand variable names in yaml.go, add better comments, improve errors, add copyright
  > 4924d91 expand variable names in fields.go
  > 59dc8b4 add 1.16 and 1.17 to github workflows
  > 740b971 remove vendor folder
bumping google.golang.org/genproto/googleapis/api d307bd8...49dd2c1:
  > 49dd2c1 chore(all): update all (# 1067)
  > e917dd1 chore(deps): bump golang.org/x/net in /googleapis/api/servicecontrol (# 1063)
  > 8102cb6 chore(deps): bump golang.org/x/net in /googleapis/api/servicemanagement (# 1060)
  > baa7128 chore(deps): bump golang.org/x/net in /googleapis/api/apikeys (# 1062)
  > 67c69aa chore(deps): bump golang.org/x/net in /googleapis/bytestream (# 1061)
  > e298162 chore(deps): bump golang.org/x/net in /googleapis/api/serviceusage (# 1064)
  > 378ed82 chore(deps): bump golang.org/x/net in /googleapis/api (# 1065)
  > a6244dc chore(deps): bump golang.org/x/net from 0.14.0 to 0.17.0 (# 1066)
  > 8bfb1ae chore(all): update all (# 1059)
  > ceb4ed7 chore(all): auto-regenerate .pb.go files (# 1058)
bumping golang.org/x/sync 22ba207...10739b0:
  > 10739b0 all: update go directive to 1.18
bumping google.golang.org/api 5e4c19e...0d3b865:
  > 0d3b865 chore(main): release 0.149.0 (# 2230)
  > c84e6ff feat(all): auto-regenerate discovery clients (# 2242)
  > e5a53db chore(all): update all (# 2233)
  > 576f5e1 feat(all): auto-regenerate discovery clients (# 2241)
  > 3151bd7 feat(all): auto-regenerate discovery clients (# 2240)
  > cf09469 feat(all): auto-regenerate discovery clients (# 2239)
  > 8d66391 feat(all): auto-regenerate discovery clients (# 2238)
  > 3cc10bf feat(all): auto-regenerate discovery clients (# 2237)
  > da38ebd feat(all): auto-regenerate discovery clients (# 2236)
  > cc28ceb feat(all): auto-regenerate discovery clients (# 2235)
  > 8bb5867 feat(all): auto-regenerate discovery clients (# 2234)
  > a1fb230 feat(all): auto-regenerate discovery clients (# 2232)
  > 9835f38 feat(all): auto-regenerate discovery clients (# 2231)
  > 199783c feat(all): auto-regenerate discovery clients (# 2229)
bumping google.golang.org/genproto/googleapis/rpc e917dd1...49dd2c1:
  > 49dd2c1 chore(all): update all (# 1067)

Signed-off-by: Knative Automation <automation@knative.team>
2023-11-08 20:44:33 +00:00
..
goyaml.v2 upgrade to latest dependencies (#806) 2023-11-08 20:44:33 +00:00
.gitignore upgrade to latest dependencies (#539) 2021-09-29 06:14:22 -07:00
.travis.yml upgrade to latest dependencies (#539) 2021-09-29 06:14:22 -07:00
CONTRIBUTING.md Migrate caching to go mod (#258) 2020-04-27 14:35:51 -07:00
LICENSE upgrade to latest dependencies (#806) 2023-11-08 20:44:33 +00:00
README.md upgrade to latest dependencies (#539) 2021-09-29 06:14:22 -07:00
RELEASE.md Migrate caching to go mod (#258) 2020-04-27 14:35:51 -07:00
SECURITY_CONTACTS Migrate caching to go mod (#258) 2020-04-27 14:35:51 -07:00
code-of-conduct.md Migrate caching to go mod (#258) 2020-04-27 14:35:51 -07:00
fields.go upgrade to latest dependencies (#806) 2023-11-08 20:44:33 +00:00
yaml.go upgrade to latest dependencies (#806) 2023-11-08 20:44:33 +00:00
yaml_go110.go upgrade to latest dependencies (#806) 2023-11-08 20:44:33 +00:00

README.md

YAML marshaling and unmarshaling support for Go

Build Status

kubernetes-sigs/yaml is a permanent fork of ghodss/yaml.

Introduction

A wrapper around go-yaml designed to enable a better way of handling YAML when marshaling to and from structs.

In short, this library first converts YAML to JSON using go-yaml and then uses json.Marshal and json.Unmarshal to convert to or from the struct. This means that it effectively reuses the JSON struct tags as well as the custom JSON methods MarshalJSON and UnmarshalJSON unlike go-yaml. For a detailed overview of the rationale behind this method, see this blog post.

Compatibility

This package uses go-yaml and therefore supports everything go-yaml supports.

Caveats

Caveat #1: When using yaml.Marshal and yaml.Unmarshal, binary data should NOT be preceded with the !!binary YAML tag. If you do, go-yaml will convert the binary data from base64 to native binary data, which is not compatible with JSON. You can still use binary in your YAML files though - just store them without the !!binary tag and decode the base64 in your code (e.g. in the custom JSON methods MarshalJSON and UnmarshalJSON). This also has the benefit that your YAML and your JSON binary data will be decoded exactly the same way. As an example:

BAD:
	exampleKey: !!binary gIGC

GOOD:
	exampleKey: gIGC
... and decode the base64 data in your code.

Caveat #2: When using YAMLToJSON directly, maps with keys that are maps will result in an error since this is not supported by JSON. This error will occur in Unmarshal as well since you can't unmarshal map keys anyways since struct fields can't be keys.

Installation and usage

To install, run:

$ go get sigs.k8s.io/yaml

And import using:

import "sigs.k8s.io/yaml"

Usage is very similar to the JSON library:

package main

import (
	"fmt"

	"sigs.k8s.io/yaml"
)

type Person struct {
	Name string `json:"name"` // Affects YAML field names too.
	Age  int    `json:"age"`
}

func main() {
	// Marshal a Person struct to YAML.
	p := Person{"John", 30}
	y, err := yaml.Marshal(p)
	if err != nil {
		fmt.Printf("err: %v\n", err)
		return
	}
	fmt.Println(string(y))
	/* Output:
	age: 30
	name: John
	*/

	// Unmarshal the YAML back into a Person struct.
	var p2 Person
	err = yaml.Unmarshal(y, &p2)
	if err != nil {
		fmt.Printf("err: %v\n", err)
		return
	}
	fmt.Println(p2)
	/* Output:
	{John 30}
	*/
}

yaml.YAMLToJSON and yaml.JSONToYAML methods are also available:

package main

import (
	"fmt"

	"sigs.k8s.io/yaml"
)

func main() {
	j := []byte(`{"name": "John", "age": 30}`)
	y, err := yaml.JSONToYAML(j)
	if err != nil {
		fmt.Printf("err: %v\n", err)
		return
	}
	fmt.Println(string(y))
	/* Output:
	age: 30
	name: John
	*/
	j2, err := yaml.YAMLToJSON(y)
	if err != nil {
		fmt.Printf("err: %v\n", err)
		return
	}
	fmt.Println(string(j2))
	/* Output:
	{"age":30,"name":"John"}
	*/
}