config

package
v0.0.0-...-99e2fb8 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(ctx logging.Context, cfg *Config) error

func ConfigureWithData

func ConfigureWithData(ctx logging.Context, data []byte) error

func Evaluate

func Evaluate(cfg *Config) error

func ParseConditions

func ParseConditions(r Registry, list []Condition) ([]logging.Condition, error)

func RegisterCondition

func RegisterCondition(name string, ty ConditionType)

func RegisterRule

func RegisterRule(name string, ty RuleType)

func RegisterValueType

func RegisterValueType(name string, ty ValueType)

Types

type AndType

AndType should be []Condition, but this does not work with Go Generics so, just explode the type, and it magically works.

func (AndType) Create

func (e AndType) Create(r Registry) (logging.Condition, error)

type AttributeType

type AttributeType struct {
	Name  string `json:"name"`
	Value Value  `json:"value,omitempty"`
}

func (*AttributeType) Create

func (e *AttributeType) Create(r Registry) (logging.Condition, error)

type Condition

type Condition = scheme.Element[ConditionType]

func And

func And(conds ...Condition) Condition

func Attribute

func Attribute(name string, value interface{}) Condition

func Not

func Not(c Condition) Condition

func Or

func Or(conds ...Condition) Condition

func Realm

func Realm(tag string) Condition

func RealmPrefix

func RealmPrefix(tag string) Condition

func Tag

func Tag(tag string) Condition

type ConditionType

type ConditionType = scheme.Factory[logging.Condition, Registry]

type ConditionalRuleType

type ConditionalRuleType struct {
	Level      string      `json:"level"`
	Conditions []Condition `json:"conditions"`
}

func (*ConditionalRuleType) Create

func (r *ConditionalRuleType) Create(reg Registry) (logging.Rule, error)

type Config

type Config struct {
	DefaultLevel string `json:"defaultLevel,omitempty"`
	Rules        []Rule `json:"rules,omitempty"`
}

func EvaluateFromData

func EvaluateFromData(data []byte) (*Config, error)

func (*Config) UnmarshalFrom

func (c *Config) UnmarshalFrom(data []byte) error

type GenericValueType

type GenericValueType struct {
	Value interface{}
}

func (GenericValueType) Create

func (m GenericValueType) Create(r Registry) (interface{}, error)

func (GenericValueType) MarshalJSON

func (m GenericValueType) MarshalJSON() ([]byte, error)

MarshalJSON returns m as the JSON encoding of m.

func (*GenericValueType) UnmarshalJSON

func (m *GenericValueType) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data.

type NotType

type NotType struct {
	Condition `json:",inline"`
}

func (*NotType) Create

func (e *NotType) Create(r Registry) (logging.Condition, error)

type OrType

type OrType AndType

func (OrType) Create

func (e OrType) Create(r Registry) (logging.Condition, error)

type RealmPrefixType

type RealmPrefixType string

func (RealmPrefixType) Create

type RealmType

type RealmType string

func (RealmType) Create

func (e RealmType) Create(_ Registry) (logging.Condition, error)

type Registry

type Registry interface {
	RegisterRuleType(name string, ty RuleType)
	RegisterConditionType(name string, ty ConditionType)
	RegisterValueType(name string, ty ValueType)

	CreateConditionFromElement(e *Condition) (logging.Condition, error)
	CreateRuleFromElement(e *Rule) (logging.Rule, error)
	CreateValueFromElement(e *Value) (any, error)
	CreateCondition(data []byte) (logging.Condition, error)
	CreateRule(data []byte) (logging.Rule, error)
	CreateValue(data []byte) (any, error)

	Evaluate(cfg *Config) error
	EvaluateFromData(data []byte) (*Config, error)

	Configure(ctx logging.Context, cfg *Config) error
	ConfigureWithData(ctx logging.Context, data []byte) error

	Copy() Registry
}

func DefaultRegistry

func DefaultRegistry() Registry

func NewRegistry

func NewRegistry() Registry

type Rule

type Rule = scheme.Element[RuleType]

func ConditionalRule

func ConditionalRule(level string, conds ...Condition) Rule

type RuleType

type RuleType = scheme.Factory[logging.Rule, Registry]

type TagType

type TagType string

func (TagType) Create

func (e TagType) Create(_ Registry) (logging.Condition, error)

type Value

type Value = scheme.Element[ValueType]

func GenericValue

func GenericValue(v interface{}) Value

type ValueType

type ValueType = scheme.Factory[any, Registry]

Jump to

Keyboard shortcuts

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