config

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 15 Imported by: 69

Documentation

Index

Constants

View Source
const (
	Byte  = Size(1)
	KByte = 1000 * Byte
	MByte = 1000 * KByte
	GByte = 1000 * MByte
	TByte = 1000 * GByte
)

Variables

This section is empty.

Functions

func DecodeTOML

func DecodeTOML(r io.Reader, v any) error

DecodeTOML decodes toml from r in to v. Requires strict field matches and returns full toml.StrictMissingError details.

func Flatten

func Flatten(errs ...error) (flat []error)

Flatten calls `Unwrap() []error` on each error and subsequent returned error that implement the method, returning a fully flattened sequence.

func MultiErrorList

func MultiErrorList(err error) (int, error)

MultiErrorList returns an error which formats underlying errors as a list, or nil if err is nil.

func NamedMultiErrorList

func NamedMultiErrorList(err error, name string) error

func Validate

func Validate(cfg any) (err error)

Validate returns any errors from calling Validated.ValidateConfig on cfg and any nested types that implement Validated.

Types

type Duration

type Duration struct {
	// contains filtered or unexported fields
}

Duration is a non-negative time duration.

func MustNewDuration

func MustNewDuration(d time.Duration) *Duration

func NewDuration

func NewDuration(d time.Duration) (Duration, error)

func ParseDuration

func ParseDuration(s string) (Duration, error)

func (Duration) Before

func (d Duration) Before(t time.Time) time.Time

Before returns the time d units before time t

func (Duration) Duration

func (d Duration) Duration() time.Duration

func (Duration) IsInstant

func (d Duration) IsInstant() bool

IsInstant is true if and only if d is of duration 0

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements the text.Marshaler interface.

func (*Duration) Scan

func (d *Duration) Scan(v any) (err error)

func (Duration) Shorter

func (d Duration) Shorter(od Duration) bool

Shorter returns true if and only if d is shorter than od.

func (Duration) String

func (d Duration) String() string

String returns a string representing the duration in the form "72h3m0.5s". Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. The zero duration formats as 0s.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(input []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(input []byte) error

UnmarshalText implements the text.Unmarshaler interface.

func (Duration) Value

func (d Duration) Value() (driver.Value, error)

type ErrEmpty

type ErrEmpty struct {
	Name string
	Msg  string
}

func (ErrEmpty) Error

func (e ErrEmpty) Error() string

type ErrInvalid

type ErrInvalid struct {
	Name  string
	Value any
	Msg   string
}

func NewErrDuplicate

func NewErrDuplicate(name string, value any) ErrInvalid

NewErrDuplicate returns an ErrInvalid with a standard duplicate message.

func (ErrInvalid) Error

func (e ErrInvalid) Error() string

type ErrMissing

type ErrMissing struct {
	Name string
	Msg  string
}

func (ErrMissing) Error

func (e ErrMissing) Error() string

type KeyNotFoundError

type KeyNotFoundError struct {
	ID      string
	KeyType string
}

func (KeyNotFoundError) Error

func (e KeyNotFoundError) Error() string

type Rate added in v0.8.0

type Rate struct {
	Limit rate.Limit
	Burst int
}

Rate includes a per second limit and a burst. Rates >= 1 are printed as "<rate>rps:<burst>". Rates < 1 are printed as "every<duration>:<burst>".

func ParseRate added in v0.8.0

func ParseRate(s string) (Rate, error)

ParseRate parses a two part rate limit & burst. They must be separated by a ':'. Limit comes first, either in the form every<int duration>, or <float count>rps. Burst comes second, as an integer.

func (Rate) String added in v0.8.0

func (r Rate) String() string

type SecretString added in v0.5.0

type SecretString string

SecretString is a string that formats and encodes redacted, as "xxxxx".

func NewSecretString added in v0.5.0

func NewSecretString(s string) *SecretString

func (SecretString) GoString added in v0.5.0

func (s SecretString) GoString() string

func (SecretString) MarshalText added in v0.5.0

func (s SecretString) MarshalText() ([]byte, error)

func (SecretString) String added in v0.5.0

func (s SecretString) String() string

type SecretURL added in v0.5.0

type SecretURL URL

SecretURL is a URL that formats and encodes redacted, as "xxxxx".

func MustSecretURL added in v0.5.0

func MustSecretURL(u string) *SecretURL

func NewSecretURL added in v0.5.0

func NewSecretURL(u *URL) *SecretURL

func (*SecretURL) GoString added in v0.5.0

func (s *SecretURL) GoString() string

func (*SecretURL) MarshalText added in v0.5.0

func (s *SecretURL) MarshalText() ([]byte, error)

func (*SecretURL) String added in v0.5.0

func (s *SecretURL) String() string

func (*SecretURL) URL added in v0.5.0

func (s *SecretURL) URL() *url.URL

func (*SecretURL) UnmarshalText added in v0.5.0

func (s *SecretURL) UnmarshalText(text []byte) error

type Size added in v0.8.0

type Size int

Size represents size in bytes, and formats with a suffix.

func ParseByte added in v0.8.0

func ParseByte(s string) (b Size, err error)

func SizeOf added in v0.9.7

func SizeOf[B ~[]byte](bs ...B) (s Size)

SizeOf returns the cumulative len of the byte slice arguments as a Size.

func (Size) MarshalText added in v0.8.0

func (b Size) MarshalText() ([]byte, error)

func (Size) String added in v0.8.0

func (b Size) String() string

func (*Size) UnmarshalText added in v0.8.0

func (b *Size) UnmarshalText(bs []byte) error

UnmarshalText parses a size from bs in to s.

type URL

type URL url.URL

URL extends url.URL to implement encoding.TextMarshaler.

func MustParseURL

func MustParseURL(s string) *URL

func ParseURL

func ParseURL(s string) (*URL, error)

func (*URL) IsZero

func (u *URL) IsZero() bool

func (*URL) MarshalText

func (u *URL) MarshalText() ([]byte, error)

func (*URL) String

func (u *URL) String() string

func (*URL) URL

func (u *URL) URL() *url.URL

URL returns a copy of u as a *url.URL

func (*URL) UnmarshalText

func (u *URL) UnmarshalText(input []byte) error

type UniqueStrings

type UniqueStrings map[string]struct{}

UniqueStrings is a helper for tracking unique values in string form.

func (UniqueStrings) IsDupe

func (u UniqueStrings) IsDupe(s *string) bool

IsDupe returns true if the set already contains the string, otherwise false. Non-nil/empty strings are added to the set.

func (UniqueStrings) IsDupeFmt

func (u UniqueStrings) IsDupeFmt(t fmt.Stringer) bool

IsDupeFmt is like IsDupe, but calls String().

type Validated

type Validated interface {
	// ValidateConfig returns nil if the config is valid, otherwise an error describing why it is invalid.
	//
	// For implementations:
	//  - Use package multierr to accumulate all errors, rather than returning the first encountered.
	//  - If an anonymous field also implements ValidateConfig(), it must be called explicitly!
	ValidateConfig() error
}

Validated configurations impose constraints that must be checked.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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