YAML support for the Go language.

Related tags

Configuration yaml
Overview

YAML support for the Go language

Introduction

The yaml package enables Go programs to comfortably encode and decode YAML values. It was developed within Canonical as part of the juju project, and is based on a pure Go port of the well-known libyaml C library to parse and generate YAML data quickly and reliably.

Compatibility

The yaml package supports most of YAML 1.1 and 1.2, including support for anchors, tags, map merging, etc. Multi-document unmarshalling is not yet implemented, and base-60 floats from YAML 1.1 are purposefully not supported since they're a poor design and are gone in YAML 1.2.

Installation and usage

The import path for the package is gopkg.in/yaml.v2.

To install it, run:

go get gopkg.in/yaml.v2

API documentation

If opened in a browser, the import path itself leads to the API documentation:

API stability

The package API for yaml v2 will remain stable as described in gopkg.in.

License

The yaml package is licensed under the Apache License 2.0. Please see the LICENSE file for details.

Example

package main

import (
        "fmt"
        "log"

        "gopkg.in/yaml.v2"
)

var data = `
a: Easy!
b:
  c: 2
  d: [3, 4]
`

// Note: struct fields must be public in order for unmarshal to
// correctly populate the data.
type T struct {
        A string
        B struct {
                RenamedC int   `yaml:"c"`
                D        []int `yaml:",flow"`
        }
}

func main() {
        t := T{}
    
        err := yaml.Unmarshal([]byte(data), &t)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        fmt.Printf("--- t:\n%v\n\n", t)
    
        d, err := yaml.Marshal(&t)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        fmt.Printf("--- t dump:\n%s\n\n", string(d))
    
        m := make(map[interface{}]interface{})
    
        err = yaml.Unmarshal([]byte(data), &m)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        fmt.Printf("--- m:\n%v\n\n", m)
    
        d, err = yaml.Marshal(&m)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        fmt.Printf("--- m dump:\n%s\n\n", string(d))
}

This example will generate the following output:

--- t:
{Easy! {2 [3 4]}}

--- t dump:
a: Easy!
b:
  c: 2
  d: [3, 4]


--- m:
map[a:Easy! b:map[c:2 d:[3 4]]]

--- m dump:
a: Easy!
b:
  c: 2
  d:
  - 3
  - 4
Comments
  • Feature (v3): Add a function to set the desired line length of an Encoder

    Feature (v3): Add a function to set the desired line length of an Encoder

    This PR exposes a function func (e *Encoder) SetLineLength(characters int) that allows setting the line wrap length of an encoder. The interface was intended to have a very similar style to the SetIndent function func (e *Encoder) SetIndent(spaces int), implemented here.

    Internally, it uses the existing function func yaml_emitter_set_width(emitter *yaml_emitter_t, width int), which was previously unused.

    This relates to several issues (#387, #348, #166) and a previous PR (#329).

    opened by laverya 33
  • Please allow the struct tag to be changed to

    Please allow the struct tag to be changed to "json"

    I find no way to tell the yaml package to just use "json" as the tag. This is quite unfortunate because I have no control over the generated structs (which are actually produced by the protobuf compiler and get json tags by default) but I need to parse these from YAML.

    I would be rather trivial to provide an option as the name of the tag to use. TBH the state of go right now is that most people add json tags to their structs but not yaml tags. It is quite pointless to add multiple tags and often we have no control over the structs (because they came from someone else's code).

    This has been hacked around in the past using e.g. github.com/ghodss/yaml but it is fragile and hacky. The easier solution for us right now is to just fork this repo and do a 3 char change :-).

    opened by scudette 32
  • Feature request: json.RawMessage equivalent

    Feature request: json.RawMessage equivalent

    It would be great to have sth. similar to http://golang.org/pkg/encoding/json/#RawMessage.

    I'm using go-yaml in http://github.com/michaelsauter/crane and would like to unmarshal the JSON/YAML partially (to provide defaults for objects inside arrays).

    enhancement thinking 
    opened by michaelsauter 31
  • v3: panic

    v3: panic "attempted to parse unknown event (please report): none"

    Hi folks 👋🏻 Found this panic (along with #665) while fuzzing my own project.

    Minimal example of the panic (https://play.golang.org/p/gLM_eHzcrgz):

    package main
    
    import (
    	"gopkg.in/yaml.v3"
    )
    
    func main() {
    	var t interface{}
    	yaml.Unmarshal([]byte("0: [:!00 \xef"), &t)
    }
    

    Output:

    panic: internal error: attempted to parse unknown event (please report): none [recovered]
    	panic: internal error: attempted to parse unknown event (please report): none
    
    goroutine 1 [running]:
    gopkg.in/yaml%2ev3.handleErr(0xc000043f60)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/yaml.go:294 +0x85
    panic(0x50f120, 0xc000010330)
    	/usr/local/go-faketime/src/runtime/panic.go:969 +0x1b9
    gopkg.in/yaml%2ev3.(*parser).parse(0xc000036c00, 0x0)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/decode.go:163 +0x277
    gopkg.in/yaml%2ev3.(*parser).parseChild(...)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/decode.go:194
    gopkg.in/yaml%2ev3.(*parser).sequence(0xc000036c00, 0xc00000e007)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/decode.go:259 +0xff
    gopkg.in/yaml%2ev3.(*parser).parse(0xc000036c00, 0x0)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/decode.go:154 +0xe7
    gopkg.in/yaml%2ev3.(*parser).parseChild(0xc000036c00, 0xc00007e3c0, 0xc00007e460)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/decode.go:194 +0x2f
    gopkg.in/yaml%2ev3.(*parser).mapping(0xc000036c00, 0x9)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/decode.go:285 +0x1ad
    gopkg.in/yaml%2ev3.(*parser).parse(0xc000036c00, 0xc000000003)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/decode.go:152 +0x10d
    gopkg.in/yaml%2ev3.(*parser).parseChild(...)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/decode.go:194
    gopkg.in/yaml%2ev3.(*parser).document(0xc000036c00, 0x3)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/decode.go:203 +0x8b
    gopkg.in/yaml%2ev3.(*parser).parse(0xc000036c00, 0x0)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/decode.go:156 +0x87
    gopkg.in/yaml%2ev3.unmarshal(0xc00002c590, 0xa, 0xa, 0x50a080, 0xc000010320, 0x0, 0x0, 0x0)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/yaml.go:161 +0x26a
    gopkg.in/yaml%2ev3.Unmarshal(...)
    	/tmp/gopath818249317/pkg/mod/gopkg.in/[email protected]/yaml.go:89
    main.main()
    	/tmp/sandbox604520862/prog.go:9 +0x99
    
    opened by bradleyjkemp 23
  • Revert

    Revert "Set the default line length to infinity (-1) (#571)"

    This reverts commit 0b1645d91e851e735d3e23330303ce81f70adbe3.

    Hi, At kubernetes, we are having a hard time with this change as it changes default behavior with no recourse to setting a custom width (to what it was before). Please see the following scenarios we hit recently:

    • https://github.com/kubernetes/kubernetes/pull/95571#issuecomment-708796327
    • https://github.com/kubernetes/kubernetes/pull/96425#issuecomment-725858135

    Signed-off-by: Davanum Srinivas [email protected]

    opened by dims 21
  • Support (un)marshaling of comments

    Support (un)marshaling of comments

    Reopening from #129

    It would be useful if go-yaml supported outputting comments when marshaling an object into YAML.

    The relevant bits of the YAML specification:

    • Intro to comments: http://yaml.org/spec/1.2/spec.html#id2767100
    • Comment specification: http://yaml.org/spec/1.2/spec.html#id2780069
    • See also http://yaml.org/spec/1.2/spec.html#id2762313

    Comments can be useful to provide human-readable information about the contents of a YAML document without affecting the actual content of the YAML itself. For instance, comments could be used to provide documentation about fields in generated configuration information, or to point out errors in the configuration (e.g. "key A may only have values X, Y, or Z").

    opened by DirectXMan12 21
  • Support map with custom order

    Support map with custom order

    The proper way to support this would be with something like:

    type MapSlice []MapItem
    
    type MapItem struct {
            Key, Value interface{}
    }
    

    and then implement first-class marshalling and unmarshalling of maps onto it.

    Feature requested via the pull request #27.

    opened by niemeyer 21
  • Support CRLF endings

    Support CRLF endings

    Witnessed behavior

    go-yaml does not support CRLF line endings when reading a file directly (which would be the main use case). For instance, the following code won't work if the loaded file is written on Windows:

    type Auth struct {
    	Customer struct {
    		Key    string
    		Secret string
    	}
    	App struct {
    		Key    string
    		Secret string
    	}
    }
    
    func main() {
    	data, err := ioutil.ReadFile("./secret.yml")
    	if err != nil {
    		fmt.Println(err.Error())
    		os.Exit(1)
    	}
    
    	a := Auth{}
    	err = yaml.Unmarshal(data, &a)
    	if err != nil {
    		fmt.Println(err.Error())
    		os.Exit(1)
    	}
    	fmt.Println(a)
    }
    

    With the following file content:

    --- 
    app:
      key: 10475405799b09120-vSkxPPI9HsWN61vO4DroQUGFpgNCs2
      secret: Z6nG4UInQVWx7Sagpmu6GsUYWZsvd5E6uIbPdlW8csfemaxm
    customer:
      key: JA2PXLd8qeXTDpx7UccWsvp60V6
      secret: qOsUM6996LQSkRw9HsnxyU3EVJzACIOEUxCBTiOcTELTF800VVQ
    

    Here's the error: yaml: line 3: mapping values are not allowed in this context

    Expected behavior

    Just work as usual.

    opened by owlscode 16
  • Comment marshaling and unmarshaling support

    Comment marshaling and unmarshaling support

    This introduces support for marshaling and unmarshaling comments.

    Some key points:

    • Comment unmarshaling is opt-in.
    • We don't retain indentation information for comments. Comments are placed at the same indentation level as the previous token.
    • The implementation uses the exact same structure as all current YAML tokens (so it's tokenized, an event is pushed, etc).
    opened by autrilla 16
  • Empty document

    Empty document "---" should not reset input object

    So, yaml.Unmarshal([]byte("---"), &out) reset the out, including yaml:"-" fields and including lower case fields. And no way to catch it.

    For example

    package main
    
    import (
    	"encoding/json"
    	"fmt"
    	"log"
    	"runtime"
    
    	"gopkg.in/yaml.v2"
    )
    
    type Target struct {
    	OS   string
    	Arch string
    }
    
    func (t *Target) SetDefault() {
    	t.OS = runtime.GOOS
    	t.Arch = runtime.GOARCH
    }
    
    func (t *Target) UnmarshalYAML(
    	unmarshalFunc func(interface{}) error,
    ) (
    	err error,
    ) {
    	// https://play.golang.org/p/PFA0BzK0S6c
    	type target Target
    	var temp = target(*t)
    	if err = unmarshalFunc(&temp); err != nil {
    		return
    	}
    	if temp.OS != "" {
    		t.OS = temp.OS
    	}
    	if temp.Arch != "" {
    		t.Arch = temp.Arch
    	}
    	return
    }
    
    type Content struct {
    	Target Target
    	Hidden bool `yaml:"-" json:"-"`
    	hidden bool
    }
    
    func (c *Content) SetDefault() {
    	c.Target.SetDefault()
    	c.Hidden = true
    	c.hidden = true
    }
    
    func (c *Content) UnmarshalYAML(
    	unmarshalFunc func(interface{}) error,
    ) (
    	err error,
    ) {
    	type content Content
    	var temp = content(*c)
    	if err = unmarshalFunc(&temp); err != nil {
    		return
    	}
    	if temp == (content{}) {
    		return // just a blank content structure
    	}
    	(*c) = Content(temp)
    	return
    }
    
    type Input struct {
    	Yaml string
    	Json string
    }
    
    func main() {
    	var (
    		c   Content
    		err error
    	)
    
    	for _, in := range []Input{
    		{
    			``,
    			`{}`, // blank string is not valid for the encoding/json
    		},
    		{
    			`---`,
    			`{}`,
    		},
    		{
    			`---
    required: yes`,
    			`{"required":true}`,
    		},
    		{
    			`---
    target: {}`,
    			`{"target":{}}`,
    		},
    		{
    			`---
    target:
      os: plan9
      arch: mips32le`,
    			`{"target":{"os":"plan9","arch":"mips32le"}}`,
    		},
    	} {
    		fmt.Println("----")
    		fmt.Println("YAML:", in.Yaml)
    		fmt.Println("JSON:", in.Json)
    
    		c.SetDefault()
    		fmt.Println("populated:   ", c)
    
    		// yaml
    		if err = yaml.Unmarshal([]byte(in.Yaml), &c); err != nil {
    			log.Fatal(err)
    		}
    		fmt.Println("yaml decoded:", c)
    
    		c.SetDefault()
    
    		// json
    		if err = json.Unmarshal([]byte(in.Json), &c); err != nil {
    			log.Fatal(err)
    		}
    		fmt.Println("json decoded:", c)
    	}
    
    }
    

    Output will be (note: only the second case has meaning)

    ----
    YAML: 
    JSON: {}
    populated:    {{linux amd64} true true}
    yaml decoded: {{linux amd64} true true}
    json decoded: {{linux amd64} true true}
    ----
    YAML: ---
    JSON: {}
    populated:    {{linux amd64} true true}
    yaml decoded: {{ } false false}
    json decoded: {{linux amd64} true true}
    ----
    YAML: ---
    required: yes
    JSON: {"required":true}
    populated:    {{linux amd64} true true}
    yaml decoded: {{linux amd64} true true}
    json decoded: {{linux amd64} true true}
    ----
    YAML: ---
    target: {}
    JSON: {"target":{}}
    populated:    {{linux amd64} true true}
    yaml decoded: {{linux amd64} true true}
    json decoded: {{linux amd64} true true}
    ----
    YAML: ---
    target:
      os: plan9
      arch: mips32le
    JSON: {"target":{"os":"plan9","arch":"mips32le"}}
    populated:    {{linux amd64} true true}
    yaml decoded: {{plan9 mips32le} true true}
    json decoded: {{plan9 mips32le} true true}
    

    The UnmarshalYAML methods don't make sense.

    opened by logrusorgru 15
  • Optimize a couple of nested loops in the scanner.

    Optimize a couple of nested loops in the scanner.

    There are two places in scannerc.go where we iterate through the full simple_keys stack that I think we can avoid:

    I've included a couple of test cases that show the bad behavior, even with the recent depth limits :

    $ git checkout c9e8ea1b90fe07c9447c7cbcc212e927d6988388 && go test -run=NONE -bench=. -benchmem ./... > old.txt
    $ git checkout 3717a577a65196747809a63ffe76c5ca6b0d88e8 && go test -run=NONE -bench=. -benchmem ./... > new.txt
    $ benchcmp old.txt new.txt 
    benchmark                                old ns/op       new ns/op      delta
    Benchmark1000KB100Aliases-6              1056925022      1094599057     +3.56%
    Benchmark1000KBDeeplyNestedSlices-6      282869888       7835556        -97.23%
    Benchmark1000KBDeeplyNestedMaps-6        266289230       7375439        -97.23%
    Benchmark1000KBDeeplyNestedIndents-6     4360666         4514662        +3.53%
    Benchmark1000KB1000IndentLines-6         449900306       451543002      +0.37%
    Benchmark1KBMaps-6                       599228          620644         +3.57%
    Benchmark10KBMaps-6                      5801815         5892398        +1.56%
    Benchmark100KBMaps-6                     53699570        57544454       +7.16%
    Benchmark1000KBMaps-6                    513662800       538354297      +4.81%
    BenchmarkDeepSlice-6                     46967064873     448771530      -99.04%
    BenchmarkDeepFlow-6                      45121229024     648750899      -98.56%
    
    benchmark                                old allocs     new allocs     delta
    Benchmark1000KB100Aliases-6              5832441        5832438        -0.00%
    Benchmark1000KBDeeplyNestedSlices-6      9068           9249           +2.00%
    Benchmark1000KBDeeplyNestedMaps-6        9072           9252           +1.98%
    Benchmark1000KBDeeplyNestedIndents-6     10082          10084          +0.02%
    Benchmark1000KB1000IndentLines-6         4093516        4093517        +0.00%
    Benchmark1KBMaps-6                       3126           3128           +0.06%
    Benchmark10KBMaps-6                      30780          30782          +0.01%
    Benchmark100KBMaps-6                     307269         307271         +0.00%
    Benchmark1000KBMaps-6                    3072079        3072082        +0.00%
    BenchmarkDeepSlice-6                     2048121        2048304        +0.01%
    BenchmarkDeepFlow-6                      3334112        3334113        +0.00%
    
    benchmark                                old bytes     new bytes     delta
    Benchmark1000KB100Aliases-6              393120640     393118752     -0.00%
    Benchmark1000KBDeeplyNestedSlices-6      4689806       4748760       +1.26%
    Benchmark1000KBDeeplyNestedMaps-6        4690070       4749212       +1.26%
    Benchmark1000KBDeeplyNestedIndents-6     2969933       2970002       +0.00%
    Benchmark1000KB1000IndentLines-6         143718544     143718560     +0.00%
    Benchmark1KBMaps-6                       218984        219112        +0.06%
    Benchmark10KBMaps-6                      2178160       2178284       +0.01%
    Benchmark100KBMaps-6                     22002813      22002938      +0.00%
    Benchmark1000KBMaps-6                    220560496     220560768     +0.00%
    BenchmarkDeepSlice-6                     120114824     120174234     +0.05%
    BenchmarkDeepFlow-6                      190656952     190656984     +0.00%
    
    
    opened by cjcullen 14
  • v3: panic (hash of unhashable type map)

    v3: panic (hash of unhashable type map)

    Minimal example of the panic(https://go.dev/play/p/r5lt0EVJAxy):

    package main
    
    import (
    	"gopkg.in/yaml.v3"
    )
    
    func main() {
    	var t interface{}
    	yaml.Unmarshal([]byte("?\n<<:\n ? 0:"), &t)
    }
    

    Output:

    panic: runtime error: hash of unhashable type map[interface {}]interface {} [recovered]
    	panic: runtime error: hash of unhashable type map[interface {}]interface {}
    
    goroutine 1 [running]:
    gopkg.in/yaml%2ev3.handleErr(0xc000051ee8)
    	/tmp/gopath584265875/pkg/mod/gopkg.in/[email protected]/yaml.go:294 +0x6d
    panic({0x4ee980, 0xc000014430})
    	/usr/local/go-faketime/src/runtime/panic.go:884 +0x212
    gopkg.in/yaml%2ev3.(*decoder).mapping(0xc0001095e0, 0xc0000006e0, {0x4ee200?, 0xc000016630?, 0x7f275d3ed1a0?})
    	/tmp/gopath584265875/pkg/mod/gopkg.in/[email protected]/decode.go:835 +0x898
    gopkg.in/yaml%2ev3.(*decoder).unmarshal(0xc0001095e0, 0xc0000006e0, {0x4ee200?, 0xc000016630?, 0x7f275d3e4108?})
    	/tmp/gopath584265875/pkg/mod/gopkg.in/[email protected]/decode.go:510 +0x3eb
    gopkg.in/yaml%2ev3.(*decoder).merge(0xc0001095e0, 0xc000000460?, 0xc0000006e0, {0x4ee200?, 0xc000016630?, 0x194?})
    	/tmp/gopath584265875/pkg/mod/gopkg.in/[email protected]/decode.go:973 +0x245
    gopkg.in/yaml%2ev3.(*decoder).mapping(0xc0001095e0, 0xc000000460, {0x4ecca0?, 0xc000014370?, 0x0?})
    	/tmp/gopath584265875/pkg/mod/gopkg.in/[email protected]/decode.go:856 +0xb94
    gopkg.in/yaml%2ev3.(*decoder).unmarshal(0xc0001095e0, 0xc000000460, {0x4ecca0?, 0xc000014370?, 0x0?})
    	/tmp/gopath584265875/pkg/mod/gopkg.in/[email protected]/decode.go:510 +0x3eb
    gopkg.in/yaml%2ev3.(*decoder).document(0x0?, 0x0?, {0x4ecca0?, 0xc000014370?, 0xc000044c00?})
    	/tmp/gopath584265875/pkg/mod/gopkg.in/[email protected]/decode.go:527 +0x5b
    gopkg.in/yaml%2ev3.(*decoder).unmarshal(0xc0001095e0, 0xc0000003c0, {0x4ecca0?, 0xc000014370?, 0x0?})
    	/tmp/gopath584265875/pkg/mod/gopkg.in/[email protected]/decode.go:498 +0x42d
    gopkg.in/yaml%2ev3.unmarshal({0xc00001c590, 0xb, 0xb}, {0x4e6b60?, 0xc000014370}, 0xe0?)
    	/tmp/gopath584265875/pkg/mod/gopkg.in/[email protected]/yaml.go:167 +0x426
    gopkg.in/yaml%2ev3.Unmarshal(...)
    	/tmp/gopath584265875/pkg/mod/gopkg.in/[email protected]/yaml.go:89
    main.main()
    	/tmp/sandbox3232958416/prog.go:9 +0x71
    
    Program exited.
    
    opened by dsp25no 2
  • isZero implementation doesn't respect `TextMarshaler` interface

    isZero implementation doesn't respect `TextMarshaler` interface

    The isZero implementation handles different types. For structs that only have private members the isZero method always returns true: https://github.com/go-yaml/yaml/blob/f6f7691b1fdeb513f56608cd2c32c51f8194bf51/yaml.go#L695

    However if that struct implements the TextMarshaler interface this leads to an unexpected encoding when having the omitempty tag.

    For example in the following playground: https://go.dev/play/p/999EoR75jxK the Invisible field has the omitempty tag and is not printed, despite having the exact same (non-empty) content as the Visible field.

    opened by lukedirtwalker 0
  • Encoder never ends on data with cycles

    Encoder never ends on data with cycles

    Data with cycles cause the encoder to never return.

    Example: https://go.dev/play/p/sWfo5Hj4M6V

    The encoder could at least detect the cycle and return an error like the json package does, or even in some cases use a reference to represent the cycle pointer.

    opened by fgm 0
  • Compact seq indent

    Compact seq indent

    This is a follow-up for https://github.com/go-yaml/yaml/pull/753 fixes https://github.com/go-yaml/yaml/issues/720

    this is required for compose-go to adopt go-yaml.v3, see https://github.com/compose-spec/compose-go/pull/153

    opened by ndeloof 0
  • Keys are always lowercase?

    Keys are always lowercase?

    I have the following example application:

    package main
    
    import (
      "log"
      yaml "gopkg.in/yaml.v3"
    )
    
    /* this type is protobuf-generated, so it cannot change */
    type ApplicationYaml struct {
      TypeId uint32 `protobuf:"varint,1,opt,name=type_id,json=typeId,proto3" json:"type_id,omitempty"`
      NrDecimals  uint32 `protobuf:"varint,6,opt,name=nr_decimals,json=nrDecimals,proto3" json:"nr_decimals,omitempty"`
      SystemdServiceName string       `protobuf:"bytes,3,opt,name=systemd_service_name,json=systemdServiceName,proto3" json:"systemd_service_name,omitempty"`
    }
    
    var yamlData = `
    typeId: 3
    type_id: 4
    typeid: 5
    TypeId: 6
    
    nrdecimals: 13
    nrDecimals: 14
    nr_decimals: 15
    NrDecimals: 16
    
    systemdservicename: foo
    systemdServiceName: bar
    systemd_service_name: baz
    SystemdServiceName: quux
    `
    
    func main() {
      app := &ApplicationYaml{}
      if err := yaml.Unmarshal([]byte(yamlData), app); err == nil {
        log.Printf("have application: %+v", app)
      } else {
        log.Printf("have err: %+v", err)
      }
    }
    

    I would have expected the output to be almost anything other than the actual output:

    have application: &{TypeId:5 NrDecimals:13 SystemdServiceName:foo}
    

    Having no yaml: annotation on the unmarshaled type, I would expect either GolangCasing, typical json camelCasing, or a fallback to the json: annotation underscore_casing to be used. But, instead, all-lowercase casing is used, very unexpectedly for me since nothing at all is asking for that case change. Is this a bug? Is there a way to influence this behavior if the type we unmarshal into is generated code, so we cannot add a yaml: annotation?

    opened by sgielen 2
  • Next Line (x85), Line Separator (x2028) and Paragraph Separator (x2029) are not treated as regular characters

    Next Line (x85), Line Separator (x2028) and Paragraph Separator (x2029) are not treated as regular characters

    Under Unicode these characters are treated as line-break characters, however the YAML spec treats them as content characters that can be part of scalars. https://yaml.org/spec/1.2.2/#54-line-break-characters

    For LS and PS, this is a change from YAML 1.1 to YAML 1.2, which this library may intentionally be keeping in order to maintain backwards compatibility. It is worth noting, however practical this is, it still breaks compatibility with the official 1.2 standard. Cases where a YAML 1.2 document contains these characters in a scalar or an anchor, for instance, will not be parsed correctly. Over 10 years on from the release of YAML 1.2, it may be considering shifting to the new standard.

    opened by michaelruigrok 0
Owner
null
Go-yaml - Yaml parsing Toolkit For Golang

go-yaml 介绍 gopkg.in/yaml.v3 已经是个非常好用的包,但是在实际开发中总有类型转换带来的麻烦,go-yaml只是在它的基础上,简单的一层

xiaowu 4 Jan 13, 2022
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

koanf (pronounced conf; a play on the Japanese Koan) is a library for reading configuration from different sources in different formats in Go applicat

Kailash Nadh 1.4k Jan 8, 2023
Golang Configuration tool that support YAML, JSON, TOML, Shell Environment

Configor Golang Configuration tool that support YAML, JSON, TOML, Shell Environment (Supports Go 1.10+) Usage package main import ( "fmt" "github.c

Jinzhu 1.5k Dec 29, 2022
Generic templating tool with support of JSON, YAML and TOML data

gotempl Small binary used to generate files from Go Templates and data files. The following formats are supported: JSON YAML TOML Usage usage: gotempl

Link Society 7 Jun 15, 2022
JSON or YAML configuration wrapper with convenient access methods.

Config Package config provides convenient access methods to configuration stored as JSON or YAML. This is a fork of the original version. This version

Oleg Lebedev 260 Dec 16, 2022
Library providing routines to merge and validate JSON, YAML and/or TOML files

CONFLATE Library providing routines to merge and validate JSON, YAML, TOML files and/or structs (godoc) Typical use case: Make your application config

Andy 26 Sep 26, 2022
A better way to marshal and unmarshal YAML in Golang

YAML marshaling and unmarshaling support for Go Introduction A wrapper around go-yaml designed to enable a better way of handling YAML when marshaling

Sam Ghods 965 Jan 4, 2023
create a bootable disk image from Docker image or a yaml config

docker2boot docker2boot creates a bootable disk from either a Docker image or a config yaml file Features status dns Y cloud-init Y network Y ssh TODO

Bin Chen 7 Oct 30, 2022
It syncronizes the configuration described in a YAML file against your GitHub Organization

It syncronizes the configuration described in a YAML file against your GitHub Organization. Combined with a CI system, it can be used to implement GitOps for GitHub.

Carlos Tadeu Panato Junior 6 Jul 19, 2021
Golang library for reading properties from configuration files in JSON and YAML format or from environment variables.

go-config Golang library for reading properties from configuration files in JSON and YAML format or from environment variables. Usage Create config in

null 3 Aug 22, 2022
Golang config.yaml loader

Description goconfig is a configuration library designed using the following pri

null 2 May 31, 2022
Tmpl - A tool to apply variables from cli, env, JSON/TOML/YAML files to templates

tmpl allows to apply variables from JSON/TOML/YAML files, environment variables or CLI arguments to template files using Golang text/template and functions from the Sprig project.

krako 2 Nov 14, 2022
SmartYAML - Go package to handle YAML

SmartYAML - Go package to handle YAML The smartyaml is a go package to handle parsed YAML files more confortable. This package is not a parser, it use

Péter Deák 0 Feb 25, 2022
VINYL Inscribes Nettlesome YAML Legibly

VINYL Inscribes Nettlesome YAML Legibly VINYL formats yaml files into a canonical format retaining comments and setting the indentation by default to

Jesse Hathaway 1 Jan 18, 2022
Go-config - Config parser for go that supports environment vars and multiple yaml files

go-multiconfig This package is able to parse yaml config files. It supports gett

Dimitris Tassopoulos 1 Jun 23, 2022
HCL is the HashiCorp configuration language.

HCL HCL is a toolkit for creating structured configuration languages that are both human- and machine-friendly, for use with command-line tools. Altho

HashiCorp 4.5k Jan 9, 2023
Go library for the TOML language

go-toml Go library for the TOML format. This library supports TOML version v1.0.0-rc.3 Features Go-toml provides the following features for using data

Thomas Pelletier 1.4k Dec 27, 2022
Tom's Obvious, Minimal Language

TOML Tom's Obvious, Minimal Language. By Tom Preston-Werner, Pradyun Gedam, et al. This repository contains the in-development version of the TOML spe

TOML 17.8k Jan 2, 2023