manager

package
v0.0.0-...-6ef3c0b Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKey    = errors.New("invalid key")
	ErrInvalidStruct = errors.New("invalid struct type")
	ErrKeyNotFound   = errors.New("key not found")
)
View Source
var AutoFormat string = ""
View Source
var ErrUnknownFormat = errors.New("unknown format")

Functions

func ConvertAnyMapToStringMapRecursive

func ConvertAnyMapToStringMapRecursive(result map[string]any, m map[any]any)

func ConvertAnyRecursive

func ConvertAnyRecursive(v any) any

func FindByExtension

func FindByExtension(ext string) string

func GetDecoderOptions

func GetDecoderOptions(name string) map[string]string

func GetEncoderOptions

func GetEncoderOptions(name string) map[string]string

func GetExtensions

func GetExtensions(name string) []string

func GetFormats

func GetFormats() []string

func GobEncoder

func GobEncoder(w io.Writer) (Encoder, Closer)

func HCL2Encoder

func HCL2Encoder(w io.Writer) (Encoder, Closer)

func MsgPackEncoder

func MsgPackEncoder(w io.Writer) (Encoder, Closer)

func RegisterFormat

func RegisterFormat(name string, exts []string, enc EncoderFactory, dec DecoderFactory)

func RegisterFormatWithOptions

func RegisterFormatWithOptions(name string, exts []string, enc EncoderFactory, encOpts any, dec DecoderFactory, decOpts any)

func ReplaceFormat

func ReplaceFormat(name string, exts []string, enc EncoderFactory, dec DecoderFactory)

func TraverseKeys

func TraverseKeys(s any, keys []string) (any, error)

func TraversePath

func TraversePath(s any, path string) (any, error)

func UnregisterFormat

func UnregisterFormat(name string)

Types

type CSVOptions

type CSVOptions struct {
	Separator string `json:"sep"`
}

func (*CSVOptions) CSVDecoder

func (opts *CSVOptions) CSVDecoder(r io.Reader) Decoder

func (*CSVOptions) CSVEncoder

func (opts *CSVOptions) CSVEncoder(w io.Writer) (Encoder, Closer)

func (*CSVOptions) Validate

func (opts *CSVOptions) Validate() error

type Closer

type Closer func() error

type Decoder

type Decoder interface {
	// Decode reads the next encoded value from its input and stores it in
	// the value pointed to by v.
	Decode(v any) error
}

func AutoDecoder

func AutoDecoder(r io.Reader) Decoder

func EDNDecoder

func EDNDecoder(r io.Reader) Decoder

EDNDecoder currently decodes any key, not just string, so it behaves differently from other decoders.

func GobDecoder

func GobDecoder(r io.Reader) Decoder

func HCL2Decoder

func HCL2Decoder(r io.Reader) Decoder

func JSONDecoder

func JSONDecoder(r io.Reader) Decoder

func MsgPackDecoder

func MsgPackDecoder(r io.Reader) Decoder

func TOMLDecoder

func TOMLDecoder(r io.Reader) Decoder

func ToDecoder

func ToDecoder(f func(io.Reader) (any, error), r io.Reader) Decoder

ToDecoder converts a function that reads from an io.Reader into a Decoder.

func YAMLDecoder

func YAMLDecoder(r io.Reader) Decoder

type DecoderFactory

type DecoderFactory func(io.Reader) Decoder

func GetDecoderFactory

func GetDecoderFactory(name string, opts map[string]string) (DecoderFactory, error)

type DecoderFunc

type DecoderFunc func(any) error

DecoderFunc is an adapter to allow the use of ordinary functions as Decoders.

func (DecoderFunc) Decode

func (f DecoderFunc) Decode(v any) error

type Document

type Document any

type DocumentGroup

type DocumentGroup struct {
	Name      string          `json:"name"`
	Documents []*DocumentInfo `json:"documents"`
}

type DocumentInfo

type DocumentInfo struct {
	SrcName  string    `json:"source_name"`
	SrcIndex int       `json:"source_index"`
	Document *Document `json:"document"`
}

type EDNEncoder

type EDNEncoder struct {
	Prefix string `json:"prefix"`
	Indent int    `json:"indent,string"`
}

func (*EDNEncoder) EncodeTo

func (e *EDNEncoder) EncodeTo(w io.Writer) (Encoder, Closer)

type Encoder

type Encoder interface {
	Encode(v any) error
}

type EncoderFactory

type EncoderFactory func(io.Writer) (Encoder, Closer)

func GetEncoderFactory

func GetEncoderFactory(name string, opts map[string]string) (EncoderFactory, error)

type EncoderFunc

type EncoderFunc func(v any) error

func (EncoderFunc) Encode

func (f EncoderFunc) Encode(v any) error

type JSONEncoder

type JSONEncoder struct {
	Indent   int  `json:"indent,string"`
	NoIndent bool `json:"no_indent,string"`
}

func (*JSONEncoder) EncodeTo

func (e *JSONEncoder) EncodeTo(w io.Writer) (Encoder, Closer)

type LogfmtOptions

type LogfmtOptions struct{}

func (*LogfmtOptions) LogfmtDecoder

func (opts *LogfmtOptions) LogfmtDecoder(r io.Reader) Decoder

func (*LogfmtOptions) LogfmtEncoder

func (opts *LogfmtOptions) LogfmtEncoder(w io.Writer) (Encoder, Closer)

func (*LogfmtOptions) Validate

func (opts *LogfmtOptions) Validate() error

type Manager

type Manager struct {
	Version string           `json:"version"`
	Groups  []*DocumentGroup `json:"document_groups"`
}

Manager is a file processor.

  • Read documents from a file or a reader. Each source becomes a group of documents.
  • A group has some metadata.
  • Optionally, sort the documents.
  • Optionally, regroup the documents.
  • Write the documents to a file or a writer. Each group becomes a single instance of a writer. Up to the writer to determine how multiple documents are written out.

func New

func New() *Manager

func (*Manager) AllInOne

func (m *Manager) AllInOne() error

AllInOne merges documents from all groups into a single group.

func (*Manager) Copy

func (m *Manager) Copy() *Manager

func (*Manager) Emit

func (m *Manager) Emit(wcf WriteCloserFactory, format string, opts map[string]string) error

func (*Manager) EmitRaw

func (m *Manager) EmitRaw(w io.Writer, format string, opts map[string]string) error

func (*Manager) Filter

func (m *Manager) Filter(expr string, include bool) error

func (*Manager) GroupBy

func (m *Manager) GroupBy(expr string) error

GroupBy regroups documents based on the result of evaluating the expression. The document is available as `doc` in the expression.

func (*Manager) Len

func (m *Manager) Len() int

func (*Manager) ProcessAll

func (m *Manager) ProcessAll(files []string, opts map[string]string) error

func (*Manager) ProcessDir

func (m *Manager) ProcessDir(dir string, opts map[string]string) error

func (*Manager) ProcessFile

func (m *Manager) ProcessFile(file string, opts map[string]string) error

func (*Manager) ProcessReader

func (m *Manager) ProcessReader(name string, in io.Reader, format string, opts map[string]string) error

func (*Manager) SortBy

func (m *Manager) SortBy(expr string) error

SortBy sorts documents in each group based on the result of evaluating the expression. The two documents being compared are available as `a.doc` and `b.doc`. See also SortByFunc.

func (*Manager) SortByFunc

func (m *Manager) SortByFunc(expr string, reverse bool) error

SortByFunc sorts documents in each group based on the result of evaluating the expression. The value of the document is available as `doc`. See also SortBy.

XXX(ripta): this doesn't work when expr is complex, e.g.: doc.apiVersion + "." + doc.kind + "/" + doc.metadata.name

type OnceDecoder

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

OnceDecoder is a decoder that only decodes the first value from its input. Subsequent calls to Decode will return io.EOF. This is useful when handling formats that do not have multidocument support, e.g., TOML.

func (*OnceDecoder) Decode

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

type TOMLEncoder

type TOMLEncoder struct {
	Indent int `json:"indent,string"`
}

func (*TOMLEncoder) EncodeTo

func (e *TOMLEncoder) EncodeTo(w io.Writer) (Encoder, Closer)

type Validator

type Validator interface {
	Validate() error
}

type WriteCloserFactory

type WriteCloserFactory func(group *DocumentGroup) (io.WriteCloser, error)

func AlwaysNoCloseWriter

func AlwaysNoCloseWriter(w io.Writer) WriteCloserFactory

func AlwaysWriter

func AlwaysWriter(w io.WriteCloser) WriteCloserFactory

func DynamicFileWriter

func DynamicFileWriter(filePattern string, fileFlag int, fileMode os.FileMode) (WriteCloserFactory, error)

DynamicFileWriter returns a new file handle for each write. The file name is generated by applying the given template to the input value. It is up to the caller to set the correct file mode and flags.

func MemoryWriter

func MemoryWriter(buf *bytes.Buffer) WriteCloserFactory

MemoryWriter writes to the given buffer. The buffer must not be nil.

func SingleFileWriter

func SingleFileWriter(file string) (WriteCloserFactory, error)

SingleFileWriter always returns the same file handle for writing. The handle is opened before the first write.

type YAMLEncoder

type YAMLEncoder struct {
	Indent int `json:"indent,string"`
}

func (*YAMLEncoder) EncodeTo

func (e *YAMLEncoder) EncodeTo(w io.Writer) (Encoder, Closer)

Jump to

Keyboard shortcuts

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