YAML in Go

Direct answer

In Go, load YAML with a maintained library such as gopkg.in/yaml.v3, prefer safe/typed APIs for untrusted input, and validate files before deploy.

Libraries

Common choice: gopkg.in/yaml.v3.

Safe load example

import "gopkg.in/yaml.v3"
var cfg Config
err := yaml.Unmarshal(buf, &cfg)

Common pitfalls

  • Prefer yaml.v3 over deprecated glide + yaml.v2 workflows
  • Define structs with yaml tags
  • Check errors from Unmarshal

Related

Validation tips

  • Unit-test loading of fixture YAML in CI.
  • Reject documents that fail safe/typed parse.
  • Cross-check ambiguous scalars with the 1.1 vs 1.2 guide.
  • Use the browser validator for quick private checks.

When not to use YAML

If you need comment-preserving round trips, binary data, or strict schema-first APIs, consider whether JSON Schema + JSON, or a purpose-built config format, fits better — then convert only at boundaries.