silly

package module
v2.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrUnsupportedKind

type ErrUnsupportedKind struct {
	// contains filtered or unexported fields
}

ErrUnsupportedKind is the error that is returned if the yaml.Node's kind is not supported.

func (ErrUnsupportedKind) Error

func (err ErrUnsupportedKind) Error() string

Error implements the error interface.

type Slice

type Slice[T any] []T

Slice represents a slice that can also be represented by a single object for a single-item slice.

func (*Slice[T]) UnmarshalYAML

func (s *Slice[T]) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL