metadecoders

package
v0.125.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 17 Imported by: 28

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = Decoder{
	Delimiter: ',',
}

Default is a Decoder in its default configuration.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// Delimiter is the field delimiter used in the CSV decoder. It defaults to ','.
	Delimiter rune

	// Comment, if not 0, is the comment character used in the CSV decoder. Lines beginning with the
	// Comment character without preceding whitespace are ignored.
	Comment rune

	// If true, a quote may appear in an unquoted field and a non-doubled quote
	// may appear in a quoted field. It defaults to false.
	LazyQuotes bool
}

Decoder provides some configuration options for the decoders.

func (Decoder) FormatFromContentString

func (d Decoder) FormatFromContentString(data string) Format

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) OptionsKey

func (d Decoder) OptionsKey() string

OptionsKey is used in cache keys.

func (Decoder) Unmarshal

func (d Decoder) Unmarshal(data []byte, f Format) (any, error)

Unmarshal will unmarshall data in format f into an interface{}. This is what's needed for Hugo's /data handling.

func (Decoder) UnmarshalFileToMap

func (d Decoder) UnmarshalFileToMap(fs afero.Fs, filename string) (map[string]any, error)

UnmarshalFileToMap is the same as UnmarshalToMap, but reads the data from the given filename.

func (Decoder) UnmarshalStringTo added in v0.56.0

func (d Decoder) UnmarshalStringTo(data string, typ any) (any, error)

UnmarshalStringTo tries to unmarshal data to a new instance of type typ.

func (Decoder) UnmarshalTo added in v0.74.0

func (d Decoder) UnmarshalTo(data []byte, f Format, v any) error

UnmarshalTo unmarshals data in format f into v.

func (Decoder) UnmarshalToMap

func (d Decoder) UnmarshalToMap(data []byte, f Format) (map[string]any, error)

UnmarshalToMap will unmarshall data in format f into a new map. This is what's needed for Hugo's front matter decoding.

type Format

type Format string
const (
	// These are the supported metadata  formats in Hugo. Most of these are also
	// supported as /data formats.
	ORG  Format = "org"
	JSON Format = "json"
	TOML Format = "toml"
	YAML Format = "yaml"
	CSV  Format = "csv"
	XML  Format = "xml"
)

func FormatFromString

func FormatFromString(formatStr string) Format

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

func FormatFromStrings(ss ...string) Format

FormatFromStrings returns the first non-empty Format from the given strings.

Jump to

Keyboard shortcuts

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