rules

package
v3.30.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Channel          = "channel"
	DataCenter       = "dataCenter"
	DataCenterIn     = "dataCenterIn"
	DeviceCountry    = "deviceCountry"
	DeviceCountryIn  = "deviceCountryIn"
	EidAvailable     = "eidAvailable"
	EidIn            = "eidIn"
	FpdAvailable     = "fpdAvailable"
	GppSidAvailable  = "gppSidAvailable"
	GppSidIn         = "gppSidIn"
	Percent          = "percent"
	TcfInScope       = "tcfInScope"
	UserFpdAvailable = "userFpdAvailable"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node[T1 any, T2 any] struct {
	SchemaFunction  SchemaFunction[T1]
	ResultFunctions []ResultFunction[T1, T2]
	Children        map[string]*Node[T1, T2]
}

Node represents a node in the tree structure. It contains a schema function, a list of result functions, and a map of child nodes.

type ResultFuncFactory

type ResultFuncFactory[T1 any, T2 any] func(string, json.RawMessage) (ResultFunction[T1, T2], error)

ResultFuncFactory is a function that takes a function name and arguments in JSON format and returns a ResultFunction and an error. It is used to create result functions for the tree nodes based on the provided configuration.

type ResultFunction

type ResultFunction[T1 any, T2 any] interface {
	Call(payloadIn *T1, payloadOut *T2, meta ResultFunctionMeta) error
	Name() string
}

type ResultFunctionMeta

type ResultFunctionMeta struct {
	SchemaFunctionResults []SchemaFunctionStep
	AnalyticsKey          string
	RuleFired             string
	ModelVersion          string
}

type SchemaFuncFactory

type SchemaFuncFactory[T any] func(string, json.RawMessage) (SchemaFunction[T], error)

SchemaFuncFactory is a function that takes a function name and arguments in JSON format and returns a SchemaFunction and an error. It is used to create schema functions for the tree nodes based on the provided configuration.

type SchemaFunction

type SchemaFunction[T any] interface {
	Call(payload *T) (string, error)
	Name() string
}

SchemaFunction...

func NewRequestSchemaFunction

func NewRequestSchemaFunction(name string, params json.RawMessage) (SchemaFunction[openrtb_ext.RequestWrapper], error)

NewRequestSchemaFunction returns the specified schema function that operates on a request payload along with any schema function args validation errors that occurred during instantiation

type SchemaFunctionStep

type SchemaFunctionStep struct {
	FuncName   string
	FuncResult string
}

type Tree

type Tree[T1 any, T2 any] struct {
	Root             *Node[T1, T2]
	DefaultFunctions []ResultFunction[T1, T2]
	AnalyticsKey     string
	ModelVersion     string
}

Tree represents the tree structure. It contains a root node and a list of default result functions. The tree is generic and can work with any types T1 and T2. The tree is used to traverse the nodes based on the schema function results and execute the result functions.

func NewTree

func NewTree[T1 any, T2 any](builder treeBuilder[T1, T2]) (*Tree[T1, T2], error)

NewTree builds a new tree using the provided tree builder function and validates the generated tree ensuring it is well-formed.

func (*Tree[T1, T2]) Run

func (t *Tree[T1, T2]) Run(payload *T1, result *T2) error

Run attempts to walk down the tree from the root to a leaf node. Each node references a schema function to execute that returns a result that is used to compare against the node values on the level below it. If the result matches one of the node values on the next level, we move to that node, otherwise we exit. If a leaf node is reached, it's result functions are executed on the provided result payload.

Jump to

Keyboard shortcuts

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