Documentation
¶
Overview ¶
Package config contains helpers for loading and dumping TOML config files
Index ¶
Constants ¶
const ( // DefaultJSONIndent is the indentation used unless SetIndent // is called on the JSON Encoder DefaultJSONIndent = ` ` )
const ( // DefaultTOMLIndent is the indentation used unless SetIndent // is called on the TOML Encoder DefaultTOMLIndent = ` ` )
Variables ¶
var ( // ErrUnknownFormat indicates we failed to identify the format of the file ErrUnknownFormat = errors.New("file format not identified") )
Functions ¶
func Encoders ¶ added in v0.0.8
func Encoders() []string
Encoders returns all the formats we know to encode
Types ¶
type Autodetect ¶ added in v0.0.8
type Autodetect struct{}
Autodetect is a Decoder that tries all Decoders
func (*Autodetect) Decode ¶ added in v0.0.8
func (p *Autodetect) Decode(data string, v any) error
Decode takes encoded data and tries all registered decoders. Decode returns ErrUnknownFormat if all decoders fail.
type Decoder ¶ added in v0.0.8
A Decoder uses text to populate a data structure.
func NewDecoder ¶ added in v0.0.8
NewDecoder returns the decoder associated with a name or extension.
func NewDecoderByFilename ¶ added in v0.0.8
NewDecoderByFilename uses the file extension to determine the decoder.
type Encoder ¶ added in v0.0.8
Encoder serializes a data structure
func NewEncoder ¶ added in v0.0.8
NewEncoder returns a encoder for the specified format
type JSON ¶ added in v0.0.8
type JSON struct {
Indent string
}
JSON is a Encoder/Decoder for JSON
func NewJSON ¶ added in v0.0.8
func NewJSON() *JSON
NewJSON creates a new JSON Encoder/Decoder with two space indentation.
type TOML ¶ added in v0.0.8
type TOML struct {
Indent string
}
TOML is a Encoder/Decoder for TOML
func NewTOML ¶ added in v0.0.8
func NewTOML() *TOML
NewTOML creates a new TOML Encoder/Decoder with two space indentation.
type YAML ¶ added in v0.0.8
type YAML struct {
Spaces int
}
YAML is a Encoder/Decoder for YAML
func NewYAML ¶ added in v0.0.8
func NewYAML() *YAML
NewYAML creates a new YAML Encoder/Decoder with two spaces as default indentation.