xconfmap

package module
v0.165.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 2 Imported by: 35

Documentation

Overview

Example

Example usage validated configuration

package main

import (
	"errors"
	"fmt"
	"time"
)

// Config represents the receiver config settings within the collector's config.yaml
type Config struct {
	Interval       time.Duration `mapstructure:"interval"`
	NumberOfTraces int           `mapstructure:"number_of_traces"`
}

// Validate checks if the receiver configuration is valid
// this function is automatically called by the collector when it loads the configurations
// for a component
func (cfg *Config) Validate() error {
	if cfg.Interval.Minutes() < 1 {
		return errors.New("when defined, the interval has to be set to at least 1 minute (1m)")
	}

	if cfg.NumberOfTraces < 1 {
		return errors.New("number_of_traces must be greater or equal to 1")
	}
	return nil
}

// Example usage validated configuration
func main() {
	// invalid number of traces
	myCfg := Config{
		Interval:       time.Minute,
		NumberOfTraces: 0,
	}
	err := myCfg.Validate()
	fmt.Println(err)

	// invalid interval
	myCfg = Config{
		Interval:       time.Second,
		NumberOfTraces: 1,
	}
	err = myCfg.Validate()
	fmt.Println(err)

	// valid config
	myCfg = Config{
		Interval:       time.Minute,
		NumberOfTraces: 1,
	}
	err = myCfg.Validate()
	fmt.Println(err)

}
Output:
number_of_traces must be greater or equal to 1
when defined, the interval has to be set to at least 1 minute (1m)
<nil>

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToStringMapRaw added in v0.146.0

func ToStringMapRaw(conf *confmap.Conf) map[string]any

ToStringMapRaw returns the raw configuration map without sanitization. This is an experimental API and may change or be removed in future versions. The returned map may change at any time without prior notice.

Unlike confmap.Conf.ToStringMap(), this function does not sanitize the map by removing expandedValue references. This allows for configmap manipulation without destroying internal types.

func WithUnredacted added in v0.150.0

func WithUnredacted() confmap.MarshalOption

WithUnredacted returns a MarshalOption that configures the confmap to bypass redaction of opaque string values.

Types

type ExpandedValue added in v0.146.0

type ExpandedValue = internal.ExpandedValue

ExpandedValue represents a configuration value that has been expanded from a template (e.g., environment variable substitution). It contains both the parsed value and the original string representation.

This type is exposed to allow working with configuration values returned by ToStringMapRaw.

Jump to

Keyboard shortcuts

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