Skip to content

Example of adding comments to yaml structure from a struct? #842

@ghostsquad

Description

@ghostsquad

I'm looking for a way to marshal a struct with comments. Ideally, these comments are dynamic in nature, but static is acceptable. Here's an example use case:

type Foo struct {
   Bar `yaml:"bar", yaml_comment:"Bar is for doing bar things"`
}

If I were to marshal this, maybe it would look like this:

foo := foo{Bar: "my-bar"}
yaml.Marshal(&foo)
# Bar is for doing bar things
bar: my-bar

Is something like this possible? Maybe in a round-about way like with path https://github.com/goccy/go-yaml#51-print-customized-error-with-yaml-source-code ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions