config

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSparrowName is returned when the sparrow name is invalid
	ErrInvalidSparrowName = errors.New("invalid sparrow name")
	// ErrInvalidLoaderInterval is returned when the loader interval is invalid
	ErrInvalidLoaderInterval = errors.New("invalid loader interval")
	// ErrInvalidLoaderHttpURL is returned when the loader http url is invalid
	ErrInvalidLoaderHttpURL = errors.New("invalid loader http url")
	// ErrInvalidLoaderHttpRetryCount is returned when the loader http retry count is invalid
	ErrInvalidLoaderHttpRetryCount = errors.New("invalid loader http retry count")
	// ErrInvalidLoaderFilePath is returned when the loader file path is invalid
	ErrInvalidLoaderFilePath = errors.New("invalid loader file path")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// SparrowName is the DNS name of the sparrow
	SparrowName string `yaml:"name" mapstructure:"name"`
	// Loader is the configuration for the loader
	Loader LoaderConfig `yaml:"loader" mapstructure:"loader"`
	// Api is the configuration for the api server
	Api api.Config `yaml:"api" mapstructure:"api"`
	// TargetManager is the configuration for the target manager
	TargetManager targets.TargetManagerConfig `yaml:"targetManager" mapstructure:"targetManager"`
	// Telemetry is the configuration for the telemetry
	Telemetry metrics.Config `yaml:"telemetry" mapstructure:"telemetry"`
}

func (*Config) HasTargetManager added in v0.2.2

func (c *Config) HasTargetManager() bool

HasTargetManager returns true if the config has a target manager

func (*Config) HasTelemetry added in v0.5.0

func (c *Config) HasTelemetry() bool

HasTelemetry returns true if the config has telemetry enabled

func (*Config) Validate

func (c *Config) Validate(ctx context.Context) (err error)

Validate validates the startup config

type FileLoader

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

func NewFileLoader

func NewFileLoader(cfg *Config, cRuntime chan<- runtime.Config) *FileLoader

func (*FileLoader) Run

func (f *FileLoader) Run(ctx context.Context) error

Run gets the runtime configuration from the local file. The config will be loaded periodically defined by the loader interval configuration. If the interval is 0, the configuration is only fetched once and the loader is disabled.

func (*FileLoader) Shutdown added in v0.3.1

func (f *FileLoader) Shutdown(ctx context.Context)

type FileLoaderConfig

type FileLoaderConfig struct {
	Path string `yaml:"path" mapstructure:"path"`
}

FileLoaderConfig is the configuration for the file loader

type HttpLoader

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

func NewHttpLoader

func NewHttpLoader(cfg *Config, cRuntime chan<- runtime.Config) *HttpLoader

func (*HttpLoader) Run

func (h *HttpLoader) Run(ctx context.Context) error

Run gets the runtime configuration from the remote file of the configured http endpoint. The config will be loaded periodically defined by the loader interval configuration. If the interval is 0, the configuration is only fetched once and the loader is disabled.

func (*HttpLoader) Shutdown added in v0.3.1

func (hl *HttpLoader) Shutdown(ctx context.Context)

Shutdown stops the loader

type HttpLoaderConfig

type HttpLoaderConfig struct {
	Url      string             `yaml:"url" mapstructure:"url"`
	Token    string             `yaml:"token" mapstructure:"token"`
	Timeout  time.Duration      `yaml:"timeout" mapstructure:"timeout"`
	RetryCfg helper.RetryConfig `yaml:"retry" mapstructure:"retry"`
}

HttpLoaderConfig is the configuration for the http loader

type Loader

type Loader interface {
	// Run starts the loader routine.
	// The loader should be able
	// to handle all errors by itself and retry if necessary.
	// If the context is canceled,
	// the Run method returns an error.
	Run(context.Context) error
	// Shutdown stops the loader routine.
	Shutdown(context.Context)
}

func NewLoader

func NewLoader(cfg *Config, cRuntime chan<- runtime.Config) Loader

NewLoader Get a new typed runtime configuration loader

type LoaderConfig

type LoaderConfig struct {
	Type     string           `yaml:"type" mapstructure:"type"`
	Interval time.Duration    `yaml:"interval" mapstructure:"interval"`
	Http     HttpLoaderConfig `yaml:"http" mapstructure:"http"`
	File     FileLoaderConfig `yaml:"file" mapstructure:"file"`
}

LoaderConfig is the configuration for loader

func (*LoaderConfig) Validate added in v0.3.2

func (c *LoaderConfig) Validate(ctx context.Context) error

Validate validates the loader configuration

type LoaderMock added in v0.3.1

type LoaderMock struct {
	// RunFunc mocks the Run method.
	RunFunc func(contextMoqParam context.Context) error

	// ShutdownFunc mocks the Shutdown method.
	ShutdownFunc func(contextMoqParam context.Context)
	// contains filtered or unexported fields
}

LoaderMock is a mock implementation of Loader.

func TestSomethingThatUsesLoader(t *testing.T) {

	// make and configure a mocked Loader
	mockedLoader := &LoaderMock{
		RunFunc: func(contextMoqParam context.Context) error {
			panic("mock out the Run method")
		},
		ShutdownFunc: func(contextMoqParam context.Context)  {
			panic("mock out the Shutdown method")
		},
	}

	// use mockedLoader in code that requires Loader
	// and then make assertions.

}

func (*LoaderMock) Run added in v0.3.1

func (mock *LoaderMock) Run(contextMoqParam context.Context) error

Run calls RunFunc.

func (*LoaderMock) RunCalls added in v0.3.1

func (mock *LoaderMock) RunCalls() []struct {
	ContextMoqParam context.Context
}

RunCalls gets all the calls that were made to Run. Check the length with:

len(mockedLoader.RunCalls())

func (*LoaderMock) Shutdown added in v0.3.1

func (mock *LoaderMock) Shutdown(contextMoqParam context.Context)

Shutdown calls ShutdownFunc.

func (*LoaderMock) ShutdownCalls added in v0.3.1

func (mock *LoaderMock) ShutdownCalls() []struct {
	ContextMoqParam context.Context
}

ShutdownCalls gets all the calls that were made to Shutdown. Check the length with:

len(mockedLoader.ShutdownCalls())

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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