config

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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        LoaderConfig                `yaml:"loader" mapstructure:"loader"`
	Api           api.Config                  `yaml:"api" mapstructure:"api"`
	TargetManager targets.TargetManagerConfig `yaml:"targetManager" mapstructure:"targetManager"`
}

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) Validate

func (c *Config) Validate(ctx context.Context) 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.

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"`
}

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 (hl *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. Returns an error if the loader is shutdown or the context is done.

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 specific 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

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