pokanop / nostromo

👽 CLI for building powerful aliases and tools
https://nostromo.sh/
MIT License
142 stars 8 forks source link

Add YAML struct tags to all types #41

Open saheljalal opened 2 years ago

saheljalal commented 2 years ago

Forgot to add YAML struct tags so the default marshaling will just turn CamelCase fields into lowercase like camelcase.

This isn't nice so let's fix it to have the common convention of camel case keys.

RishiKumarRay commented 2 years ago

Can yo give any example of adding struct tag ?

saheljalal commented 2 years ago

@RishiKumarRay Sure, you can check the yaml package for more details here: https://github.com/go-yaml/yaml

The general idea for struct tags are to add them as part of the type definition like done here for both JSON and YAML:

type Foo struct {
    SomeVar int             `json:"someVar" yaml:"someVar"`
    AnotherVar string   `json:"anotherVar" yaml:"anotherVar"`
}

This allows marshal and unmarshal to read/write the fields as specified. Otherwise they default and in this case become lowercase keys.

For this ticket, there is a small caveat that we need to make sure we migrate from the legacy format (during first read) and then can write the new manifest. This will handle the upgrade case.

Hope this helps.