Documentation
¶
Overview ¶
Package parse provides JSON parsing for cortex rule definitions.
Index ¶
- func ParseAndBuild(name string, data []byte, config *cortex.Config) (*cortex.Engine, error)
- type AllocationDef
- type AllocationTarget
- type AssignmentDef
- type BuildupDef
- type FormulaDef
- type LookupDef
- type LookupEntry
- type LookupRuleDef
- type Parser
- func (p *Parser) ParseAndBuildEngine(name string, data []byte, config *cortex.Config) (*cortex.Engine, error)
- func (p *Parser) ParseJSON(data []byte) (*RuleSet, error)
- func (p *Parser) RegisterFormula(name string, fn cortex.FormulaFunc)
- func (p *Parser) ToLookups(rs *RuleSet) ([]cortex.Lookup, error)
- func (p *Parser) ToRules(rs *RuleSet) ([]cortex.Rule, error)
- type RuleDefinition
- type RuleSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AllocationDef ¶
type AllocationDef struct {
Source string `json:"source"`
Strategy string `json:"strategy"`
Targets []AllocationTarget `json:"targets"`
Remainder string `json:"remainder,omitempty"`
Precision int `json:"precision,omitempty"`
}
AllocationDef is the config structure for allocation rules.
type AllocationTarget ¶
AllocationTarget defines an allocation destination.
type AssignmentDef ¶
AssignmentDef is the config structure for assignment rules.
type BuildupDef ¶
type BuildupDef struct {
Buildup string `json:"buildup"`
Operation string `json:"operation"`
Source string `json:"source,omitempty"`
Initial float64 `json:"initial,omitempty"`
Target string `json:"target,omitempty"`
}
BuildupDef is the config structure for buildup rules.
type FormulaDef ¶
type FormulaDef struct {
Target string `json:"target"`
Expression string `json:"expression,omitempty"`
Function string `json:"function,omitempty"` // named registered function
Inputs []string `json:"inputs,omitempty"`
}
FormulaDef is the config structure for formula rules.
type LookupDef ¶
type LookupDef struct {
Name string `json:"name"`
Type string `json:"type"` // "map" or "range"
Entries []LookupEntry `json:"entries,omitempty"`
Items map[string]any `json:"items,omitempty"` // for map type
}
LookupDef defines a lookup table in config.
type LookupEntry ¶
type LookupEntry struct {
Min float64 `json:"min"`
Max *float64 `json:"max"` // nil means +infinity
Value any `json:"value"`
}
LookupEntry defines a single entry in a range lookup.
type LookupRuleDef ¶
type LookupRuleDef struct {
Table string `json:"table"`
Key string `json:"key"`
Target string `json:"target"`
Default any `json:"default,omitempty"`
Required bool `json:"required,omitempty"`
}
LookupRuleDef is the config structure for lookup rules.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses config into rules.
func (*Parser) ParseAndBuildEngine ¶
func (p *Parser) ParseAndBuildEngine(name string, data []byte, config *cortex.Config) (*cortex.Engine, error)
ParseAndBuildEngine parses JSON and builds an Engine.
func (*Parser) RegisterFormula ¶
func (p *Parser) RegisterFormula(name string, fn cortex.FormulaFunc)
RegisterFormula registers a named formula function for use in config.
type RuleDefinition ¶
type RuleDefinition struct {
ID string `json:"id"`
Type string `json:"type"` // assignment, formula, allocation, lookup, buildup
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Deps []string `json:"deps,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Config map[string]any `json:"config"`
}
RuleDefinition is a config-driven rule.