Parse YAML maps as single-item lists
- Go 100%
| .gitignore | ||
| .golangci.yaml | ||
| .woodpecker.yaml | ||
| errors.go | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| README.md | ||
| slice.go | ||
| slice_test.go | ||
silly - Single-Item Lists for Yaml
silly allows you to parse YAML lists you can also use with maps if the list only contains one item.
If you use silly, data: a and data: [ a ] are the same.
This also supports maps:
data:
a: b
c: d
--- # or
data:
- a: b
c: d
You can still use it as a regular YAML list:
data:
- a: b
c: d
- a: f
c: h
Requirements
- Go 1.18+ (uses generics)
- usage of
gopkg.in/yaml.v3as YAML parsing library (or any wrapper around it likecodeberg.org/6543/xyaml)
Installation
Run go get codeberg.org/qwerty287/go-silly.
Usage
silly.Slice[T] is a slice, but you can also use maps which will be converted to single-item slices.
type Example struct {
Data silly.Slice[string] `yaml:"data"`
}
After using yaml.Unmarshal, Data is a slice of items (in the example a string slice).
If you use just a single object, the slice will only contain one item.
data: a and data: [a] will both result in the same slice after unmarshalling ([a]).
Using yaml.Marshal always marshals the data as a list.