Documentation
¶
Index ¶
- Variables
- func UnmarshalYaml(data []byte, v any) error
- type Decoder
- func (d Decoder) FormatFromContentString(data string) Format
- func (d Decoder) OptionsKey() string
- func (d Decoder) Unmarshal(data []byte, f Format) (any, error)
- func (d Decoder) UnmarshalFileToMap(fs afero.Fs, filename string) (map[string]any, error)
- func (d Decoder) UnmarshalStringTo(data string, typ any) (any, error)
- func (d Decoder) UnmarshalTo(data []byte, f Format, v any) error
- func (d Decoder) UnmarshalToMap(data []byte, f Format) (map[string]any, error)
- type Format
Constants ¶
This section is empty.
Variables ¶
var Default = Decoder{
Delimiter: ',',
TargetType: "slice",
}
Default is a Decoder in its default configuration.
var MarshalYAML = func(v any) ([]byte, error) { return yaml.MarshalWithOptions(v, yamlEncodeOptions...) }
MarshalYAML marshals the given value to YAML.
Functions ¶
func UnmarshalYaml ¶ added in v0.152.0
UnmarshalYaml unmarshals data in YAML format into v.
Types ¶
type Decoder ¶
type Decoder struct {
// Format specifies a specific format to decode from. If empty or
// unspecified, it's inferred from the contents or the filename.
Format string
// Delimiter is the field delimiter. Used in the CSV decoder. Default is
// ','.
Delimiter rune
// Comment, if not 0, is the comment character. Lines beginning with the
// Comment character without preceding whitespace are ignored. Used in the
// CSV decoder.
Comment rune
// If true, a quote may appear in an unquoted field and a non-doubled quote
// may appear in a quoted field. Used in the CSV decoder. Default is false.
LazyQuotes bool
// The target data type, either slice or map. Used in the CSV decoder.
// Default is slice.
TargetType string
}
Decoder provides some configuration options for the decoders.
func (Decoder) FormatFromContentString ¶
FormatFromContentString tries to detect the format (JSON, YAML, TOML or XML) in the given string. It return an empty string if no format could be detected.
func (Decoder) Unmarshal ¶
Unmarshal will unmarshall data in format f into an interface{}. This is what's needed for Hugo's /data handling.
func (Decoder) UnmarshalFileToMap ¶
UnmarshalFileToMap is the same as UnmarshalToMap, but reads the data from the given filename.
func (Decoder) UnmarshalStringTo ¶ added in v0.56.0
UnmarshalStringTo tries to unmarshal data to a new instance of type typ.
func (Decoder) UnmarshalTo ¶ added in v0.74.0
UnmarshalTo unmarshals data in format f into v.
type Format ¶
type Format string
func FormatFromString ¶
FormatFromString turns formatStr, typically a file extension without any ".", into a Format. It returns an empty string for unknown formats.
func FormatFromStrings ¶ added in v0.112.0
FormatFromStrings returns the first non-empty Format from the given strings.