config

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: BSD-3-Clause-Clear Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLoadingConfig       = errors.New("error loading config")
	ErrUnmarshallingConfig = errors.New("error unmarshalling config")
	ErrSettingConfig       = errors.New("error setting config")
)

Functions

This section is empty.

Types

type ChangeHook

type ChangeHook func(configServices ServicesMap) error

ChangeHook is a function invoked when the configuration changes.

type Config

type Config struct {
	// DevMode specifies whether the service is running in development mode.
	DevMode bool `mapstructure:"dev_mode" json:"dev_mode"`

	// DB represents the configuration settings for the database.
	DB db.Config `mapstructure:"db" json:"db"`

	// Server represents the configuration settings for the server.
	Server server.Config `mapstructure:"server" json:"server"`

	// Logger represents the configuration settings for the logger.
	Logger logger.Config `mapstructure:"logger" json:"logger"`

	// Mode specifies which services to run.
	// By default, it runs all services.
	Mode []string `mapstructure:"mode" json:"mode" default:"[\"all\"]"`

	// SDKConfig represents the configuration settings for the SDK.
	SDKConfig SDKConfig `mapstructure:"sdk_config" json:"sdk_config"`

	// Services represents the configuration settings for the services.
	Services ServicesMap `mapstructure:"services"`

	// Trace is for configuring open telemetry based tracing.
	Trace tracing.Config `mapstructure:"trace"`
	// contains filtered or unexported fields
}

Config represents the configuration settings for the service.

func LoadConfig

func LoadConfig(_ context.Context, key, file string) (*Config, error)

LoadConfig loads configuration using the provided loader or creates a default Viper loader

func (*Config) AddLoader

func (c *Config) AddLoader(loader Loader)

AddLoader adds a configuration loader to the list of loaders.

func (*Config) AddOnConfigChangeHook

func (c *Config) AddOnConfigChangeHook(hook ChangeHook)

AddOnConfigChangeHook adds a hook to the list of hooks to call when the configuration changes.

func (*Config) Close

func (c *Config) Close(ctx context.Context) error

Close invokes close method on all config loaders.

func (*Config) LogValue

func (c *Config) LogValue() slog.Value

LogValue returns a slog.Value representation of the config. We exclude logging service configuration as it may contain sensitive information.

func (*Config) OnChange

func (c *Config) OnChange(_ context.Context) error

OnChange invokes all registered onConfigChangeHooks after a configuration change.

func (*Config) Watch

func (c *Config) Watch(ctx context.Context) error

Watch starts watching the configuration for changes in all config loaders.

type Connection

type Connection struct {
	// Endpoint is the URL of the platform or service.
	Endpoint string `mapstructure:"endpoint" json:"endpoint"`

	// Plaintext specifies whether the SDK should use plaintext communication.
	Plaintext bool `mapstructure:"plaintext" json:"plaintext" default:"false" validate:"boolean"`

	// Insecure specifies whether the SDK should use insecure TLS communication.
	Insecure bool `mapstructure:"insecure" json:"insecure" default:"false" validate:"boolean"`
}

type EnvironmentLoader

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

EnvironmentLoader implements Loader using Viper

func NewEnvironmentLoader

func NewEnvironmentLoader(key, file string) (*EnvironmentLoader, error)

NewEnvironmentLoader creates a new Viper-based configuration loader to load from environment variables, from a default or specified file (or k8s config map), or some combination

func (*EnvironmentLoader) Close

func (l *EnvironmentLoader) Close() error

Close closes the environment configuration loader

func (*EnvironmentLoader) Load

func (l *EnvironmentLoader) Load(cfg *Config) error

Load loads the configuration into the provided struct

func (*EnvironmentLoader) Name

func (l *EnvironmentLoader) Name() string

Name returns the name of the environment configuration loader

func (*EnvironmentLoader) Watch

func (l *EnvironmentLoader) Watch(ctx context.Context, cfg *Config, onChange func(context.Context) error) error

Watch starts watching the config file for configuration changes

type Loader

type Loader interface {
	// Load loads the configuration into the provided struct
	Load(cfg *Config) error
	// Watch starts watching for configuration changes and invokes an onChange callback
	Watch(ctx context.Context, cfg *Config, onChange func(context.Context) error) error
	// Close closes the configuration loader
	Close() error
	// Name returns the name of the configuration loader
	Name() string
}

Loader defines the interface for loading and managing configuration

type SDKConfig

type SDKConfig struct {
	// Connection to the Core Platform
	CorePlatformConnection Connection `mapstructure:"core" json:"core"`

	// Connection to an ERS if not in the core platform
	EntityResolutionConnection Connection `mapstructure:"entityresolution" json:"entityresolution"`

	// ClientID is the client ID used for client credentials grant.
	// It is required together with ClientSecret.
	ClientID string `mapstructure:"client_id" json:"client_id" validate:"required_with=ClientSecret"`

	// ClientSecret is the client secret used for client credentials grant.
	// It is required together with ClientID.
	ClientSecret string `mapstructure:"client_secret" json:"client_secret" validate:"required_with=ClientID"`
}

SDKConfig represents the configuration for the SDK.

func (SDKConfig) LogValue

func (c SDKConfig) LogValue() slog.Value

type ServiceConfig

type ServiceConfig map[string]any

Config structure holding a single service.

type ServicesMap

type ServicesMap map[string]ServiceConfig

Config structure holding all services.

Jump to

Keyboard shortcuts

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