config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 11 Imported by: 44

Documentation

Index

Constants

This section is empty.

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 flattend 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 interface{}) (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 interface{}) (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 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.

Jump to

Keyboard shortcuts

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