Skip to content

Instantly share code, notes, and snippets.

@rayterrill
Created June 15, 2022 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayterrill/ff2844ce336fbf1b68bc5bf6ff32d25f to your computer and use it in GitHub Desktop.
Save rayterrill/ff2844ce336fbf1b68bc5bf6ff32d25f to your computer and use it in GitHub Desktop.
Example of yaml marshal with inline map[string]interface
package main
import (
"fmt"
"gopkg.in/yaml.v3"
)
type Person struct {
ExtensionProps map[string]interface{} `yaml:",inline"`
Name string `json:"name" yaml:"name"`
Age int `json:age" yaml:"age"`
}
func main() {
ext := map[string]interface{}{
"x-something-important1": "TEST",
"x-something-important2": "TEST",
}
p := &Person{
Name: "TEST",
Age: 200,
ExtensionProps: ext,
}
y, err := yaml.Marshal(p)
if err != nil {
fmt.Printf("err: %v\n", err)
return
}
fmt.Println(string(y))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment