yaml

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultEncoderOptions = []yaml.EncodeOption{
	yaml.Indent(2),
	yaml.IndentSequence(true),
}

Functions

func DefaultLookupCommentFunc

func DefaultLookupCommentFunc(commentMap map[string]string) func(t reflect.Type, f string) string

func MergeRootFromValue added in v0.28.0

func MergeRootFromValue(data []byte, v any) ([]byte, error)

MergeRootFromValue parses YAML data, merges a value at the root, and returns the result. Comments and structure in the original data are preserved.

func NewPathBuilder

func NewPathBuilder() *yaml.PathBuilder

Types

type Decoder

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

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(v any) error

type Encoder

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

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

func (*Encoder) Close

func (e *Encoder) Close() error

func (*Encoder) Encode

func (e *Encoder) Encode(v any) error

type Error

type Error struct {
	Err         error
	Path        *yaml.Path
	Token       *token.Token
	Theme       *theme.Theme
	Formatter   string
	Source      []byte
	SourceLines int // Number of lines to show around the error in the source.
}

Error represents a YAML error. It includes the original error, and the *token.Token where the error occurred.

func NewError

func NewError(err error, opts ...ErrorOpt) *Error

func (Error) Error

func (e Error) Error() string

type ErrorOpt

type ErrorOpt func(e *Error)

func WithFormatter

func WithFormatter(formatter string) ErrorOpt

func WithPath

func WithPath(path *yaml.Path) ErrorOpt

func WithSource

func WithSource(source []byte) ErrorOpt

func WithSourceLines

func WithSourceLines(lines int) ErrorOpt

func WithTheme

func WithTheme(t *theme.Theme) ErrorOpt

func WithToken

func WithToken(tk *token.Token) ErrorOpt

type ErrorWrapper

type ErrorWrapper struct {
	Opts []ErrorOpt
}

func NewErrorWrapper

func NewErrorWrapper(opts ...ErrorOpt) *ErrorWrapper

func (*ErrorWrapper) Wrap

func (ew *ErrorWrapper) Wrap(err error, opts ...ErrorOpt) error

Wrap wraps an error with additional context for [Error]s. If the error isn't an Error, it returns the original error unmodified.

type LookupCommentFunc

type LookupCommentFunc func(commentMap map[string]string) func(t reflect.Type, f string) string

type PrintFunc

type PrintFunc func() *Property

PrintFunc returns property instance.

type Printer

type Printer struct {
	MapKey  PrintFunc
	Anchor  PrintFunc
	Alias   PrintFunc
	Bool    PrintFunc
	String  PrintFunc
	Number  PrintFunc
	Comment PrintFunc
}

Printer create text from token collection or ast. This is a simplified version of github.com/goccy/go-yaml/printer.Printer, with styling and annotation functionality removed.

func (*Printer) PrintErrorToken

func (p *Printer) PrintErrorToken(tk *token.Token, lines int) (string, int)

func (*Printer) PrintTokens

func (p *Printer) PrintTokens(tokens token.Tokens) string

PrintTokens create text from token collection.

type Property

type Property struct {
	Prefix string
	Suffix string
}

Property additional property set for each the token.

type SchemaGenerator

type SchemaGenerator struct {
	Reflector         *jsonschema.Reflector
	LookupCommentFunc LookupCommentFunc

	Tests bool // Include test files.
	// contains filtered or unexported fields
}

SchemaGenerator generates a JSON schema from a Go type using reflection. It looks up comments from the source code to provide documentation, one or more package paths are provided. Uses github.com/invopop/jsonschema.

func NewSchemaGenerator

func NewSchemaGenerator(reflectTarget any, packagePaths ...string) *SchemaGenerator

NewSchemaGenerator creates a new SchemaGenerator. The reflectTarget is the Go type to generate the schema for, and packagePaths are the fully qualified import paths of the packages to lookup comments from.

func (*SchemaGenerator) Generate

func (g *SchemaGenerator) Generate() ([]byte, error)

type Validator

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

Validator validates data against a JSON schema. Uses github.com/santhosh-tekuri/jsonschema/v6.

func MustNewValidator

func MustNewValidator(url string, schemaData []byte) *Validator

func NewValidator

func NewValidator(url string, schemaData []byte) (*Validator, error)

NewValidator creates a new Validator with the provided JSON schema data.

func (*Validator) Validate

func (s *Validator) Validate(data any) error

ValidateWithSchema validates the given data against the schema. It returns a [ValidationError] that can be used with yaml.Path.AnnotateSource for precise error reporting.

Jump to

Keyboard shortcuts

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