Created
June 15, 2022 05:53
-
-
Save rayterrill/ff2844ce336fbf1b68bc5bf6ff32d25f to your computer and use it in GitHub Desktop.
Example of yaml marshal with inline map[string]interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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