config

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: LGPL-2.1 Imports: 15 Imported by: 1

Documentation

Overview

Package config handles Skogul configuration parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRelevantRawConfigSection added in v0.7.0

func GetRelevantRawConfigSection(rawConfig *map[string]interface{}, family, section string) map[string]interface{}

GetRelevantRawConfigSection is a helper function to dig down into a Config JSON and select the wanted family (receivers, transformers, senders) and item (foo).

func VerifyOnlyRequiredConfigProps added in v0.5.1

func VerifyOnlyRequiredConfigProps(componentConfig *map[string]interface{}, family, handler string, T reflect.Type) []string

VerifyOnlyRequiredConfigProps checks for undefined configuration properties It can be used to identify typos or invalid configuration Use 'config.GetRelevantRawConfigSection' first for handler if you have a full config.

Types

type Config

type Config struct {
	Handlers     map[string]*Handler
	Receivers    map[string]*Receiver
	Senders      map[string]*Sender
	Parsers      map[string]*Parser
	Encoders     map[string]*Encoder
	Transformers map[string]*Transformer
}

Config encapsulates all configuration for Skogul, and represent the top-level configuration object.

func Bytes

func Bytes(b []byte) (*Config, error)

Bytes parses json in the provided byte array and returns a configuration.

It does this by first doing a pass where it just does JSON unmarshalling, which also updates sender and handler reference tables globally (unfortunately...), then calling secondPass(), which resolves references and does a final validation.

func File

func File(f string) (*Config, error)

File opens a config file and parses it, then returns the valid configuration, using Bytes()

func Path added in v0.10.9

func Path(path string) (*Config, error)

Path opens a path (file or directory) and parses the configuration.

func ReadFiles added in v0.7.0

func ReadFiles(p string) (*Config, error)

ReadFiles reads all JSON files (with the .JSON suffix) in a given directory and combines them to a configuration for the program.

type Encoder added in v0.15.1

type Encoder struct {
	Type    string
	Encoder skogul.Encoder `json:"-"`
}

Encoder wraps the skogul.Encoder module-type for configuration parsing.

func (*Encoder) MarshalJSON added in v0.15.1

func (e *Encoder) MarshalJSON() ([]byte, error)

MarshalJSON marshals Encoder config. See MarshalJSON for receiver - same same.

func (*Encoder) UnmarshalJSON added in v0.15.1

func (e *Encoder) UnmarshalJSON(b []byte) error

UnmarshalJSON for Parser. See UnmarshalJSON for Receiver - same same.

type FieldDoc added in v0.3.0

type FieldDoc struct {
	Doc     string
	Example string
	Type    string
}

FieldDoc is a structured representation of the documentation of a single field in a struct, used for modules

type Handler

type Handler struct {
	Parser                skogul.ParserRef
	Transformers          []*skogul.TransformerRef
	Sender                skogul.SenderRef
	IgnorePartialFailures bool
	Handler               skogul.Handler `json:"-"`
}

Handler wraps skogul.Handler for configuration parsing.

type Help

type Help struct {
	Name        string
	Aliases     string
	Doc         string
	Fields      map[string]FieldDoc
	CustomTypes map[string]map[string]FieldDoc
	AutoMake    bool
}

Help is the relevant help for a single module

func HelpModule added in v0.3.0

func HelpModule(mmap skogul.ModuleMap, mod string) (Help, error)

HelpModule looks up help for a module in the specified module map. It also fetches documentation for the struct fields, using reflection.

type Parser added in v0.9.0

type Parser struct {
	Type   string
	Parser skogul.Parser `json:"-"`
}

Parser wraps the skogul.Parser for configuration parsing.

func (*Parser) MarshalJSON added in v0.9.0

func (p *Parser) MarshalJSON() ([]byte, error)

MarshalJSON marshals Parser config. See MarshalJSON for receiver - same same.

func (*Parser) UnmarshalJSON added in v0.9.0

func (p *Parser) UnmarshalJSON(b []byte) error

UnmarshalJSON for Parser. See UnmarshalJSON for Receiver - same same.

type Receiver

type Receiver struct {
	Type     string
	Receiver skogul.Receiver `json:"-"`
}

Receiver wraps the skogul.Receiver for configuration parsing.

func (*Receiver) MarshalJSON

func (r *Receiver) MarshalJSON() ([]byte, error)

MarshalJSON for a receiver marshals the actual instantiated receiver, then merges it to add "type". Probably not the most efficient implementation, since it does marshal-unmarshal-merge-marshal, but since this isn't really performance sensitive, that's ok.

func (*Receiver) UnmarshalJSON

func (r *Receiver) UnmarshalJSON(b []byte) error

UnmarshalJSON picks up the type of the Receiver, instantiates a copy of that receiver, then unmarshals the remaining configuration onto that.

type Sender

type Sender struct {
	Type   string
	Sender skogul.Sender `json:"-"`
}

Sender wraps the skogul.Sender for configuration parsing.

func (*Sender) MarshalJSON

func (s *Sender) MarshalJSON() ([]byte, error)

MarshalJSON marshals Sender config. See MarshalJSON for receiver - same same.

func (*Sender) UnmarshalJSON

func (s *Sender) UnmarshalJSON(b []byte) error

UnmarshalJSON for Sender. See UnmarshalJSON for Receiver - same same.

type Transformer

type Transformer struct {
	Type        string
	Transformer skogul.Transformer `json:"-"`
}

Transformer wraps skogul.Transformer

func (*Transformer) MarshalJSON added in v0.28.0

func (t *Transformer) MarshalJSON() ([]byte, error)

MarshalJSON marshals Transformer config. See MarshalJSON for receiver - same same.

func (*Transformer) UnmarshalJSON

func (t *Transformer) UnmarshalJSON(b []byte) error

UnmarshalJSON picks up the type of the Receiver, instantiates a copy of that receiver, then unmarshals the remaining configuration onto that.

Jump to

Keyboard shortcuts

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