Documentation
¶
Index ¶
- Variables
- func ConvertAnyMapToStringMapRecursive(result map[string]any, m map[any]any)
- func ConvertAnyRecursive(v any) any
- func FindByExtension(ext string) string
- func GetDecoderOptions(name string) map[string]string
- func GetEncoderOptions(name string) map[string]string
- func GetExtensions(name string) []string
- func GetFormats() []string
- func GobEncoder(w io.Writer) (Encoder, Closer)
- func HCL2Encoder(w io.Writer) (Encoder, Closer)
- func MsgPackEncoder(w io.Writer) (Encoder, Closer)
- func RegisterFormat(name string, exts []string, enc EncoderFactory, dec DecoderFactory)
- func RegisterFormatWithOptions(name string, exts []string, enc EncoderFactory, encOpts any, ...)
- func ReplaceFormat(name string, exts []string, enc EncoderFactory, dec DecoderFactory)
- func TraverseKeys(s any, keys []string) (any, error)
- func TraversePath(s any, path string) (any, error)
- func UnregisterFormat(name string)
- type CSVOptions
- type Closer
- type Decoder
- func AutoDecoder(r io.Reader) Decoder
- func EDNDecoder(r io.Reader) Decoder
- func GobDecoder(r io.Reader) Decoder
- func HCL2Decoder(r io.Reader) Decoder
- func JSONDecoder(r io.Reader) Decoder
- func MsgPackDecoder(r io.Reader) Decoder
- func TOMLDecoder(r io.Reader) Decoder
- func ToDecoder(f func(io.Reader) (any, error), r io.Reader) Decoder
- func YAMLDecoder(r io.Reader) Decoder
- type DecoderFactory
- type DecoderFunc
- type Document
- type DocumentGroup
- type DocumentInfo
- type EDNEncoder
- type Encoder
- type EncoderFactory
- type EncoderFunc
- type JSONEncoder
- type LogfmtOptions
- type Manager
- func (m *Manager) AllInOne() error
- func (m *Manager) Copy() *Manager
- func (m *Manager) Emit(wcf WriteCloserFactory, format string, opts map[string]string) error
- func (m *Manager) EmitRaw(w io.Writer, format string, opts map[string]string) error
- func (m *Manager) Filter(expr string, include bool) error
- func (m *Manager) GroupBy(expr string) error
- func (m *Manager) Len() int
- func (m *Manager) ProcessAll(files []string, opts map[string]string) error
- func (m *Manager) ProcessDir(dir string, opts map[string]string) error
- func (m *Manager) ProcessFile(file string, opts map[string]string) error
- func (m *Manager) ProcessReader(name string, in io.Reader, format string, opts map[string]string) error
- func (m *Manager) SortBy(expr string) error
- func (m *Manager) SortByFunc(expr string, reverse bool) error
- type OnceDecoder
- type TOMLEncoder
- type Validator
- type WriteCloserFactory
- func AlwaysNoCloseWriter(w io.Writer) WriteCloserFactory
- func AlwaysWriter(w io.WriteCloser) WriteCloserFactory
- func DynamicFileWriter(filePattern string, fileFlag int, fileMode os.FileMode) (WriteCloserFactory, error)
- func MemoryWriter(buf *bytes.Buffer) WriteCloserFactory
- func SingleFileWriter(file string) (WriteCloserFactory, error)
- type YAMLEncoder
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidKey = errors.New("invalid key") ErrInvalidStruct = errors.New("invalid struct type") ErrKeyNotFound = errors.New("key not found") )
var AutoFormat string = ""
var ErrUnknownFormat = errors.New("unknown format")
Functions ¶
func ConvertAnyRecursive ¶
func FindByExtension ¶
func GetDecoderOptions ¶
func GetEncoderOptions ¶
func GetExtensions ¶
func GetFormats ¶
func GetFormats() []string
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 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 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 EDNDecoder ¶
EDNDecoder currently decodes any key, not just string, so it behaves differently from other decoders.
func GobDecoder ¶
func HCL2Decoder ¶
func JSONDecoder ¶
func MsgPackDecoder ¶
func TOMLDecoder ¶
func YAMLDecoder ¶
type DecoderFactory ¶
func GetDecoderFactory ¶
func GetDecoderFactory(name string, opts map[string]string) (DecoderFactory, error)
type DecoderFunc ¶
DecoderFunc is an adapter to allow the use of ordinary functions as Decoders.
func (DecoderFunc) Decode ¶
func (f DecoderFunc) Decode(v any) error
type DocumentGroup ¶
type DocumentGroup struct {
Name string `json:"name"`
Documents []*DocumentInfo `json:"documents"`
}
type DocumentInfo ¶
type EDNEncoder ¶
type EncoderFactory ¶
func GetEncoderFactory ¶
func GetEncoderFactory(name string, opts map[string]string) (EncoderFactory, error)
type EncoderFunc ¶
func (EncoderFunc) Encode ¶
func (f EncoderFunc) Encode(v any) error
type JSONEncoder ¶
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 (*Manager) GroupBy ¶
GroupBy regroups documents based on the result of evaluating the expression. The document is available as `doc` in the expression.
func (*Manager) ProcessAll ¶
func (*Manager) ProcessFile ¶
func (*Manager) ProcessReader ¶
func (*Manager) SortBy ¶
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 ¶
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"`
}
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"`
}