Help us shape the future of Go! Take the 2026 Go Developer Survey

loaders

package
v0.49.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Loaders = map[string]Initializer{}
View Source
var LoadersTypes = []string{
	"file",
	"consul",
	"docker",
	"http",
}

Functions

func BindLogger added in v0.46.0

func BindLogger(parent *slog.Logger, loaderType string) *slog.Logger

BindLogger returns a non-nil *slog.Logger annotated with the loader type. If parent is nil, a discarding logger is returned so callers never need a nil check.

func DecodeConfig

func DecodeConfig(src, dst interface{}) error

func Register

func Register(name string, initFn Initializer)

Types

type Initializer

type Initializer func() TargetLoader

type Option

type Option func(TargetLoader)

func WithActions

func WithActions(acts map[string]map[string]interface{}) Option

func WithRegistry

func WithRegistry(reg *prometheus.Registry) Option

func WithTargetsDefaults

func WithTargetsDefaults(fn func(tc *types.TargetConfig) error) Option

type TargetLoader

type TargetLoader interface {
	// Init initializes the target loader given the config, logger and options
	Init(ctx context.Context, cfg map[string]interface{}, l *slog.Logger, opts ...Option) error
	// RunOnce runs the loader only once, returning a map of target configs
	RunOnce(ctx context.Context) (map[string]*types.TargetConfig, error)
	// Start starts the target loader, running periodic polls or a long watch.
	// It returns a channel of TargetOperation from which the function caller can
	// receive the added/removed target configs
	Start(context.Context) chan *TargetOperation
	// RegsiterMetrics registers the loader metrics with the provided registry
	RegisterMetrics(*prometheus.Registry)
	// WithActions passes the actions configuration to the target loader
	WithActions(map[string]map[string]interface{})
	// WithTargetsDefaults passes a callback function that sets the target config defaults
	WithTargetsDefaults(func(tc *types.TargetConfig) error)
}

TargetLoader discovers a set of target configurations for gNMIc to run RPCs against. RunOnce should return a map of target configs and is meant to be used with Unary RPCs. Start runs a goroutine in the background that updates added/removed target configs on the returned channel.

type TargetOperation

type TargetOperation struct {
	Add map[string]*types.TargetConfig
	Del []string
}

func Diff

func Diff(currentMap, newMap map[string]*types.TargetConfig) *TargetOperation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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