config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmbeddedConfig

func EmbeddedConfig() embed.FS

EmbeddedConfig returns the embedded config filesystem for external packages to access.

func SetGlobal

func SetGlobal(updateFns ...func(config *Config))

SetGlobal updates the global configuration.

Types

type ArrayConfig

type ArrayConfig struct {
	Section

	// AutoWrapSingleValues allows to have `result: x` to be considered as `result: [x]`
	AutoWrapSingleValues bool `toml:"AutoWrapSingleValues"`
}

type BoolConfig

type BoolConfig struct {
	Section

	FallbackValue maybe.Bool `toml:"FallbackValue"`

	FromStrings *BoolFromStringsConfig `toml:"FromStrings"`
	FromNumbers *BoolFromNumbersConfig `toml:"FromNumbers"`
	FromNull    *BoolFromNullConfig    `toml:"FromNull"`
}

type BoolFromNullConfig

type BoolFromNullConfig struct {
	Section

	Inverse bool `toml:"Inverse"`
}

type BoolFromNumberAlg

type BoolFromNumberAlg uint8

BoolFromNumberAlg specifies the algorithm of how parsing Number->Bool is done.

const (
	// BoolFromNumberUndefined is the undefined value.
	BoolFromNumberUndefined BoolFromNumberAlg = 0

	// BoolFromNumberBinary is the "1/0" parser. 1 is true, 0 is false.
	// Other numbers are considered "non-parsed" (fallback value or Red result).
	BoolFromNumberBinary BoolFromNumberAlg = 1 << (iota - 1) // 1 (001)

	// BoolFromNumberPositiveNegative is the "<=0 vs >0" parser.
	// Positive numbers are true. Negative numbers And zero are false.
	BoolFromNumberPositiveNegative // 2 (010)

	// BoolFromNumberSignOfOne is the "-1/1" parser.
	// -1 means false, 1 means true. Other numbers are considered "non-parsed" (fallback value or Red result).
	BoolFromNumberSignOfOne // 4 (100)
)

func ListAvailableBoolFromNumberAlgs

func ListAvailableBoolFromNumberAlgs() []BoolFromNumberAlg

ListAvailableBoolFromNumberAlgs lists all available values of BoolFromNumberAlg.

func (*BoolFromNumberAlg) DefaultValue

func (*BoolFromNumberAlg) DefaultValue() BoolFromNumberAlg

func (*BoolFromNumberAlg) MarshalText

func (b *BoolFromNumberAlg) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for BoolFromNumberAlg. It converts an enum value into its string representation.

func (*BoolFromNumberAlg) String

func (b *BoolFromNumberAlg) String() string

String stringifies the value of BoolFromNumberAlg.

func (*BoolFromNumberAlg) UnmarshalText

func (b *BoolFromNumberAlg) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for BoolFromNumberAlg. It converts a string (e.g., "sign_of_one") into the corresponding enum value.

type BoolFromNumbersConfig

type BoolFromNumbersConfig struct {
	Section

	CustomParseFunc BoolFromNumberAlg `toml:"CustomParseFunc"`
}

type BoolFromStringsConfig

type BoolFromStringsConfig struct {
	Section

	// TODO(github.com/d3rty/json/issues/3) precache customListForTrue + CaseInsensitive (so we don't do lower of the list each time)
	CustomListForTrue       []string `toml:"CustomListForTrue"`
	CustomListForFalse      []string `toml:"CustomListForFalse"`
	CaseInsensitive         bool     `toml:"CaseInsensitive"`
	RespectFromNumbersLogic bool     `toml:"RespectFromNumbersLogic"`
}

type Config

type Config struct {
	Section

	Bool     *BoolConfig     `toml:"Bool"`
	Number   *NumberConfig   `toml:"Number"`
	Date     *DateConfig     `toml:"Date"`
	Array    *ArrayConfig    `toml:"Array"`
	FlexKeys *FlexKeysConfig `toml:"FlexKeys"`
}

Config holds global settings for dirty unmarshalling.

func Default

func Default() *Config

Default returns a copy of the loaded default config (default.toml).

func FromBytes

func FromBytes(data []byte) *Config

FromBytes read config from a given raw [] byte.

func Global

func Global() *Config

Global returns a copy of the global configuration. The returned copy is a clone. Modifying of it doesn't affect the original config.

func Load

func Load(path string) (*Config, error)

func New

func New() *Config

New creates a new and empty config.

func (*Config) Clone

func (cfg *Config) Clone() *Config

Clone returns the deep safe copy of a Config instance.

func (*Config) ResetToDefault

func (cfg *Config) ResetToDefault()

ResetToDefault resets config to the default state.

func (*Config) ResetToEmpty

func (cfg *Config) ResetToEmpty()

ResetToEmpty resets config to its clean state (clean config).

func (*Config) String

func (cfg *Config) String() string

String shows string representation of the config. It used primarily for debug purposes or verbose mode We use `toml` representation here.

type DateConfig

type DateConfig struct {
	Section

	Timezone    *DateTimezoneConfig    `toml:"Timezone"`
	FromNumbers *DateFromNumbersConfig `toml:"FromNumbers"`
	FromStrings *DateFromStringsConfig `toml:"FromStrings"`
	FromNull    *DateFromNullConfig    `toml:"FromNull"`
}

type DateFromNullConfig

type DateFromNullConfig struct {
	Section
}

type DateFromNumbersConfig

type DateFromNumbersConfig struct {
	Section

	UnixTimestamp      bool `toml:"UnixTimestamp"`
	UnixMilliTimestamp bool `toml:"UnixMilliTimestamp"`
}

type DateFromStringsConfig

type DateFromStringsConfig struct {
	Section

	Layouts struct {
		Time     []string `toml:"Time"`
		Date     []string `toml:"Date"`
		DateTime []string `toml:"DateTime"`
	} `toml:"Layouts"`
	Aliases                 bool `toml:"Aliases"`
	RespectFromNumbersLogic bool `toml:"RespectFromNumbersLogic"`
}

type DateTimezoneConfig

type DateTimezoneConfig struct {
	Section

	Default             string   `toml:"Default"`
	Fields              []string `toml:"Fields"`
	ForceConvertingInto bool     `toml:"ForceConvertingInto"`
}

type FlexKeysConfig

type FlexKeysConfig struct {
	Section

	CaseInsensitive bool `toml:"CaseInsensitive"`
	ChameleonCase   bool `toml:"ChameleonCase"`
}

type NumberConfig

type NumberConfig struct {
	Section

	FromStrings *NumberFromStringsConfig `toml:"FromStrings"`
	FromBools   *NumberFromBoolsConfig   `toml:"FromBools"`
	FromNull    *NumberFromNullConfig    `toml:"FromNull"`
}

type NumberFromBoolsConfig

type NumberFromBoolsConfig struct {
	Section
}

type NumberFromNullConfig

type NumberFromNullConfig struct {
	Section
}

type NumberFromStringsConfig

type NumberFromStringsConfig struct {
	Section

	SpacingAllowed          bool        `toml:"SpacingAllowed"`
	ExponentNotationAllowed bool        `toml:"ExponentNotationAllowed"`
	CommasAllowed           bool        `toml:"CommasAllowed"`
	RoundingAlgorithm       RoundingAlg `toml:"RoundingAlgorithm"`
}

type RoundingAlg

type RoundingAlg uint8

RoundingAlg specifies the algorithm of how parsing Number->Bool is done.

const (
	// RoundingAlgUndefined is the undefined value.
	RoundingAlgUndefined RoundingAlg = 0

	// RoundingAlgNone means integers can't be parsed from floors with non-zero decimals.
	RoundingAlgNone RoundingAlg = 1 << (iota - 1) // 1 (001)

	// RoundingAlgFloor means it uses math.Floor() when parsing integers from floats.
	RoundingAlgFloor // 2 (010)

	// RoundingAlgRound means it uses math.Round() when parsing integers from floats.
	RoundingAlgRound // 4 (100)
)

func ListAvailableRoundingAlgs

func ListAvailableRoundingAlgs() []RoundingAlg

ListAvailableRoundingAlgs lists all available values of RoundingAlg.

func (*RoundingAlg) DefaultValue

func (*RoundingAlg) DefaultValue() RoundingAlg

func (*RoundingAlg) MarshalText

func (b *RoundingAlg) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for RoundingAlg. It converts an enum value into its string representation.

func (*RoundingAlg) String

func (b *RoundingAlg) String() string

String stringifies the value of RoundingAlg.

func (*RoundingAlg) UnmarshalText

func (b *RoundingAlg) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for RoundingAlg. It converts a string (e.g., "floor") into the corresponding enum value.

type Section

type Section struct {
	Disabled bool `toml:"Disabled"`
}

Section is a config section (toml table). Section is considered disabled if Disabled=true or full its parent is nil (see cfg.init()).

func (Section) IsDisabled

func (s Section) IsDisabled() bool

IsDisabled return true if its `Disabled:true` was set in the toml.

Jump to

Keyboard shortcuts

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