Parse YAML maps as single-item lists
This repository has been archived on 2024-03-21. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
Find a file
qwerty287 b6baee6025
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
Move back
2024-01-19 16:59:11 +01:00
.gitignore Initial commit 2023-10-04 15:12:02 +02:00
.golangci.yaml Add golangci-lint 2023-10-04 15:22:21 +02:00
.woodpecker.yaml Add golangci-lint 2023-10-04 15:22:21 +02:00
errors.go Move back 2024-01-19 16:59:11 +01:00
go.mod Add v2 prefix 2024-01-19 16:54:01 +01:00
go.sum Initial commit 2023-10-04 15:12:02 +02:00
LICENSE Initial commit 2023-10-04 15:12:02 +02:00
README.md Rename to Slice only 2023-12-31 10:35:57 +01:00
slice.go Move back 2024-01-19 16:59:11 +01:00
slice_test.go Move back 2024-01-19 16:59:11 +01:00

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

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.