feat(yaml): add JSON style encoding option to NewEncoder (#2038)
This commit is contained in:
parent
84bc096576
commit
867bef0f03
|
|
@ -20,7 +20,12 @@ type Encoder interface {
|
|||
// NewEncoder creates and returns a function that is used to encode a Go object to a YAML document
|
||||
func NewEncoder(w io.Writer) Encoder {
|
||||
if runtime.GoccyGoYaml {
|
||||
return yaml.NewEncoder(w)
|
||||
yamlEncoderOpts := []yaml.EncodeOption{}
|
||||
// enable JSON style if the envvar is set
|
||||
if os.Getenv(envvar.EnableGoccyGoYamlJSONStyle) == "true" {
|
||||
yamlEncoderOpts = append(yamlEncoderOpts, yaml.JSON(), yaml.Flow(false))
|
||||
}
|
||||
return yaml.NewEncoder(w, yamlEncoderOpts...)
|
||||
}
|
||||
|
||||
return v2.NewEncoder(w)
|
||||
|
|
|
|||
Loading…
Reference in New Issue