collectorconfig

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse[T any](raw map[string]any) (T, error)

Parse parses a raw field map into a config struct T using struct tags. Unknown keys are rejected. See ParsePartial for a variant that passes unknown keys through.

Supported struct tags:

  • `config:"key_name"` — the YAML/env field name (required for the field to be parsed)
  • `default:"123"` — default value for non-pointer int fields (bool defaults to false, int defaults to 0)
  • `min:"0"` — minimum value for int fields (inclusive)
  • `max:"500"` — maximum value for int fields (inclusive)

Pointer fields (*bool, *int) default to nil (unset).

func ParseBoolValue

func ParseBoolValue(raw any) (bool, error)

ParseBoolValue converts a raw YAML/env value to bool. Accepts bool and string ("true"/"false") types.

func ParseIntValue

func ParseIntValue(raw any) (int, error)

ParseIntValue converts a raw YAML/env value to int. Accepts int, int64, float64 (no decimals), and string types.

func ParsePartial

func ParsePartial[T any](raw map[string]any) (T, map[string]any, error)

ParsePartial is like Parse but passes unknown keys through in the returned remaining map instead of rejecting them.

Types

type BaseConfig

type BaseConfig struct {
	Enabled         *bool `config:"enabled"`
	IntervalSeconds *int  `config:"interval_seconds" min:"0"`
}

BaseConfig holds universal fields that apply to every collector.

func (BaseConfig) IntervalOr

func (b BaseConfig) IntervalOr(def time.Duration) (time.Duration, error)

IntervalOr returns the configured interval or def when unset or zero. A non-zero value less than def is an error — users can slow collection down but not speed it up beyond the default.

func (BaseConfig) IsEnabled

func (b BaseConfig) IsEnabled() bool

IsEnabled returns true if the collector is not explicitly disabled.

type TypedEntry

type TypedEntry[T any] struct {
	Base  BaseConfig
	Extra T
}

TypedEntry pairs a BaseConfig with a typed per-collector config.

Jump to

Keyboard shortcuts

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