File: yaml_json.go

package info (click to toggle)
golang-github-opencontainers-runtime-tools 0.9.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,108 kB
  • sloc: sh: 557; makefile: 104
file content (22 lines) | stat: -rw-r--r-- 526 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// +build !yaml

package tap

import (
	"encoding/json"
)

// yaml serializes a message to YAML.  This implementation uses JSON,
// which is a subset of YAML [1] and is implemented by Go's standard
// library.
//
// [1]: http://www.yaml.org/spec/1.2/spec.html#id2759572
func yaml(message interface{}, prefix string) (marshaled []byte, err error) {
	marshaled, err = json.MarshalIndent(message, prefix, "  ")
	if err != nil {
		return marshaled, err
	}

	marshaled = append(marshaled, []byte("\n")...)
	return marshaled, err
}