vendor: sigs.k8s.io/yaml v1.2.0

full diff: https://github.com/kubernetes-sigs/yaml/compare/v1.1.0...v1.2.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-03-06 21:10:36 +01:00
parent 04c805e636
commit f3d062423c
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
4 changed files with 78 additions and 7 deletions

View File

@ -83,7 +83,7 @@ k8s.io/cri-api 775aa3c1cf7380ba8b7362f5a52f
k8s.io/klog 2ca9ad30301bf30a8a6e0fa2110db6b8df699a91 # v1.0.0 k8s.io/klog 2ca9ad30301bf30a8a6e0fa2110db6b8df699a91 # v1.0.0
k8s.io/kubernetes d224476cd0730baca2b6e357d144171ed74192d6 # v1.17.1 k8s.io/kubernetes d224476cd0730baca2b6e357d144171ed74192d6 # v1.17.1
k8s.io/utils e782cd3c129fc98ee807f3c889c0f26eb7c9daf5 k8s.io/utils e782cd3c129fc98ee807f3c889c0f26eb7c9daf5
sigs.k8s.io/yaml fd68e9863619f6ec2fdd8625fe1f02e7c877e480 # v1.1.0 sigs.k8s.io/yaml 9fc95527decd95bb9d28cc2eab08179b2d0f6971 # v1.2.0
# cni dependencies # cni dependencies
github.com/containerd/go-cni 0d360c50b10b350b6bb23863fd4dfb1c232b01c9 github.com/containerd/go-cni 0d360c50b10b350b6bb23863fd4dfb1c232b01c9

14
vendor/sigs.k8s.io/yaml/README.md generated vendored
View File

@ -1,12 +1,14 @@
# YAML marshaling and unmarshaling support for Go # YAML marshaling and unmarshaling support for Go
[![Build Status](https://travis-ci.org/ghodss/yaml.svg)](https://travis-ci.org/ghodss/yaml) [![Build Status](https://travis-ci.org/kubernetes-sigs/yaml.svg)](https://travis-ci.org/kubernetes-sigs/yaml)
kubernetes-sigs/yaml is a permanent fork of [ghodss/yaml](https://github.com/ghodss/yaml).
## Introduction ## Introduction
A wrapper around [go-yaml](https://github.com/go-yaml/yaml) designed to enable a better way of handling YAML when marshaling to and from structs. A wrapper around [go-yaml](https://github.com/go-yaml/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](http://ghodss.com/2014/the-right-way-to-handle-yaml-in-golang/). 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](http://web.archive.org/web/20190603050330/http://ghodss.com/2014/the-right-way-to-handle-yaml-in-golang/).
## Compatibility ## Compatibility
@ -32,13 +34,13 @@ GOOD:
To install, run: To install, run:
``` ```
$ go get github.com/ghodss/yaml $ go get sigs.k8s.io/yaml
``` ```
And import using: And import using:
``` ```
import "github.com/ghodss/yaml" import "sigs.k8s.io/yaml"
``` ```
Usage is very similar to the JSON library: Usage is very similar to the JSON library:
@ -49,7 +51,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/ghodss/yaml" "sigs.k8s.io/yaml"
) )
type Person struct { type Person struct {
@ -93,7 +95,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/ghodss/yaml" "sigs.k8s.io/yaml"
) )
func main() { func main() {

8
vendor/sigs.k8s.io/yaml/go.mod generated vendored Normal file
View File

@ -0,0 +1,8 @@
module sigs.k8s.io/yaml
go 1.12
require (
github.com/davecgh/go-spew v1.1.1
gopkg.in/yaml.v2 v2.2.8
)

61
vendor/sigs.k8s.io/yaml/yaml.go generated vendored
View File

@ -317,3 +317,64 @@ func convertToJSONableObject(yamlObj interface{}, jsonTarget *reflect.Value) (in
return yamlObj, nil return yamlObj, nil
} }
} }
// JSONObjectToYAMLObject converts an in-memory JSON object into a YAML in-memory MapSlice,
// without going through a byte representation. A nil or empty map[string]interface{} input is
// converted to an empty map, i.e. yaml.MapSlice(nil).
//
// interface{} slices stay interface{} slices. map[string]interface{} becomes yaml.MapSlice.
//
// int64 and float64 are down casted following the logic of github.com/go-yaml/yaml:
// - float64s are down-casted as far as possible without data-loss to int, int64, uint64.
// - int64s are down-casted to int if possible without data-loss.
//
// Big int/int64/uint64 do not lose precision as in the json-yaml roundtripping case.
//
// string, bool and any other types are unchanged.
func JSONObjectToYAMLObject(j map[string]interface{}) yaml.MapSlice {
if len(j) == 0 {
return nil
}
ret := make(yaml.MapSlice, 0, len(j))
for k, v := range j {
ret = append(ret, yaml.MapItem{Key: k, Value: jsonToYAMLValue(v)})
}
return ret
}
func jsonToYAMLValue(j interface{}) interface{} {
switch j := j.(type) {
case map[string]interface{}:
if j == nil {
return interface{}(nil)
}
return JSONObjectToYAMLObject(j)
case []interface{}:
if j == nil {
return interface{}(nil)
}
ret := make([]interface{}, len(j))
for i := range j {
ret[i] = jsonToYAMLValue(j[i])
}
return ret
case float64:
// replicate the logic in https://github.com/go-yaml/yaml/blob/51d6538a90f86fe93ac480b35f37b2be17fef232/resolve.go#L151
if i64 := int64(j); j == float64(i64) {
if i := int(i64); i64 == int64(i) {
return i
}
return i64
}
if ui64 := uint64(j); j == float64(ui64) {
return ui64
}
return j
case int64:
if i := int(j); j == int64(i) {
return i
}
return j
}
return j
}