yaml_encoder

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 6 Imported by: 0

README

yaml-encoder

https://github.com/zwgblue/yaml-encoder

This is a yaml encoder which implements yaml.Marshaler for marshal with comments.

Inspired by The doc's encoder of talos

Documentation

Index

Constants

View Source
const (
	AttrCommentSep = ". "
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CommentsFlag

type CommentsFlag int

CommentsFlag comments encoding flags type.

const (
	CommentsDisabled CommentsFlag = iota
	CommentsOnHead
	CommentsInLine
	CommentsOnFoot
)

type Encoder

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

Encoder implements config encoder.

func NewEncoder

func NewEncoder(value interface{}, opts ...Option) *Encoder

NewEncoder initializes and returns an `Encoder`.

func (*Encoder) Encode

func (e *Encoder) Encode() ([]byte, error)

Encode converts value to yaml.

func (*Encoder) EncodeDoc

func (e *Encoder) EncodeDoc() ([]byte, error)

EncodeDoc converts comment to json.

func (*Encoder) Marshal

func (e *Encoder) Marshal() (*yaml.Node, error)

Marshal converts value to YAML-serializable value (suitable for MarshalYAML).

type Option

type Option func(*Options)

Option gives ability to alter config encoder output settings.

func WithComments

func WithComments(flag CommentsFlag) Option

WithComments enables comments in the encoder.

func WithCommentsMap

func WithCommentsMap(m map[string]string) Option

WithCommentsMap enables comments from map.

func WithOmitEmpty

func WithOmitEmpty(value bool) Option

WithOmitEmpty toggles omitempty handling.

type Options

type Options struct {
	CommentsFlag CommentsFlag
	OmitEmpty    bool
	CommentsMap  map[string]string
}

Options defines encoder config.

Jump to

Keyboard shortcuts

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