Documentation ¶
Index ¶
- Constants
- type Operator
- type Path
- type PathEvaluator
- type PathEvaluatorBuilder
- type PathsParser
- type PathsParserBuilder
- type Projector
- type ProjectorEvaluator
- type ProjectorEvaluatorBuilder
- func (b *ProjectorEvaluatorBuilder) Build() (result *ProjectorEvaluator, err error)
- func (b *ProjectorEvaluatorBuilder) SetLogger(value *slog.Logger) *ProjectorEvaluatorBuilder
- func (b *ProjectorEvaluatorBuilder) SetPathEvaluator(value func(context.Context, Path, any) (any, error)) *ProjectorEvaluatorBuilder
- type ProjectorParser
- type ProjectorParserBuilder
- type Selector
- type SelectorEvaluator
- type SelectorEvaluatorBuilder
- func (b *SelectorEvaluatorBuilder) Build() (result *SelectorEvaluator, err error)
- func (b *SelectorEvaluatorBuilder) SetLogger(value *slog.Logger) *SelectorEvaluatorBuilder
- func (b *SelectorEvaluatorBuilder) SetPathEvaluator(value func(context.Context, Path, any) (any, error)) *SelectorEvaluatorBuilder
- type SelectorParser
- type SelectorParserBuilder
- type Term
Constants ¶
const Key = "@key"
Key is the special path segment used to represent the name of an attribute.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Operator ¶
type Operator int
Operator represents a comparison operator.
const ( // Cont checks if the attribute is a string that contains the substring given as value. Cont Operator = iota // Eq check if the attribute is equal to the value. Eq // Gt checks if the attribute is greater than the value. Gt // Gte checks if the attribute is greater or equal than the value. Gte // In checks if the attribute is one of the values. In // Lt checks if the attribute is less than the value. Lt // Lte checks if the attribute is less or equal than the value. Lte // Ncont is the negation of `cont`. It checks if the attribute is a string that does not // contain the value. Ncont // Neq is the negation of `eq`. It checks if the attribute is not equal to the value. Neq // Nin is the negation of `in`. It checks if the attribute is not one of the values. Nin )
type Path ¶
type Path []string
Path represents the path of an attribute inside a complex data type. Each value of the slice is an attribute name, starting with the outermost field name.
type PathEvaluator ¶
type PathEvaluator struct {
// contains filtered or unexported fields
}
PathEvaluator knows how extract from an object the value of an attribute given its path. Don't create instances of this type directly use the NewPathEvaluator function instead.
type PathEvaluatorBuilder ¶
type PathEvaluatorBuilder struct {
// contains filtered or unexported fields
}
PathEvaluatorBuilder contains the logic and data needed to create attribute path evaluators. Don't create instances of this type directly, use the NewPathEvaluator function instead.
func NewPathEvaluator ¶
func NewPathEvaluator() *PathEvaluatorBuilder
NewPathEvaluator creates a builder that can then be used to configure and create path evaluators.
func (*PathEvaluatorBuilder) Build ¶
func (b *PathEvaluatorBuilder) Build() (result *PathEvaluator, err error)
Build uses the configuration stored in the builder to create a new evaluator.
func (*PathEvaluatorBuilder) SetLogger ¶
func (b *PathEvaluatorBuilder) SetLogger(value *slog.Logger) *PathEvaluatorBuilder
SetLogger sets the logger that the evaluator will use to write log messages. This is mandatory.
type PathsParser ¶
type PathsParser struct {
// contains filtered or unexported fields
}
PathsParser knows how to parse field paths. Don't create instances of this type directly, use the NewPathsParser function instead.
type PathsParserBuilder ¶
type PathsParserBuilder struct {
// contains filtered or unexported fields
}
PathsParserBuilder contains the logic and data needed to create field paths parsers. Don't create instances of this type directly, use the NewPathsParser function instead.
func NewPathsParser ¶
func NewPathsParser() *PathsParserBuilder
NewPathsParser creates a builder that can then be used to configure and create path parsers.
func (*PathsParserBuilder) Build ¶
func (b *PathsParserBuilder) Build() (result *PathsParser, err error)
Build uses the configuration stored in the builder to create a new parser.
func (*PathsParserBuilder) SetLogger ¶
func (b *PathsParserBuilder) SetLogger(value *slog.Logger) *PathsParserBuilder
SetLogger sets the logger that the parser will use to write log messages. This is mandatory.
type Projector ¶
type Projector struct { // Include is the list of paths that will be included in the result when the projector // is evaluated. An empty list means that all paths will be included. Include []Path // Exclude is the list of paths that will be excluded from the result when the projector // is evaluated. An empty list means that no path will be excluded. Exclude []Path }
Projector defines how to remove fields from an object.
type ProjectorEvaluator ¶
type ProjectorEvaluator struct {
// contains filtered or unexported fields
}
ProjectorEvaluator knows how to evaluate field projection. Don't create instances of this type directly, use the NewProjectionEvaluator function instead.
type ProjectorEvaluatorBuilder ¶
type ProjectorEvaluatorBuilder struct {
// contains filtered or unexported fields
}
ProjectorEvaluatorBuilder contains the logic and data needed to create field projection evaluators. Don't create instances of this type directly, use the NewProjectorEvaluator function instead.
func NewProjectorEvaluator ¶
func NewProjectorEvaluator() *ProjectorEvaluatorBuilder
NewProjectorEvaluator creates a builder that can then be used to configure and create field selector evaluators.
func (*ProjectorEvaluatorBuilder) Build ¶
func (b *ProjectorEvaluatorBuilder) Build() (result *ProjectorEvaluator, err error)
Build uses the configuration stored in the builder to create a new evaluator.
func (*ProjectorEvaluatorBuilder) SetLogger ¶
func (b *ProjectorEvaluatorBuilder) SetLogger(value *slog.Logger) *ProjectorEvaluatorBuilder
SetLogger sets the logger that the evaluator will use to write log messages. This is mandatory.
func (*ProjectorEvaluatorBuilder) SetPathEvaluator ¶
func (b *ProjectorEvaluatorBuilder) SetPathEvaluator( value func(context.Context, Path, any) (any, error)) *ProjectorEvaluatorBuilder
SetPathEvaluator sets the function that will be used to extract values of attributes from the object. This is mandatory.
The path evaluator function receives the attribute path and the object and should return the value of that attribute. For example, for a simple struct like this:
type Person struct { Name string Age int }
The path evaluator function could be like this:
func personPathEvaluator(ctx context.Context, path Path, object any) (result any, err error) { person, ok := object.(*Person) if !ok { err = fmt.Errorf("expected person, but got '%T'", object) return } if len(path) != 1 { err = fmt.Errorf("expected exactly one path segment, but got %d", len(path)) return } segment := path[0] switch segment { case "name": result = person.Name case "age": result = person.Age default: err = fmt.Errorf( "unknown attribute '%', valid attributes are 'name' and 'age'", segment, ) } return
The path evaluator function should return an error if the object isn't of the expected type, of if the path doesn't correspond to a valid attribute.
The path evaluator function should return nil if the path corresponds to a valid optional attribute that hasn't a value.
type ProjectorParser ¶
type ProjectorParser struct {
// contains filtered or unexported fields
}
ProjectorParser knows how to parse field selectors. Don't create instances of this type directly, use the NewProjectorParser function instead.
type ProjectorParserBuilder ¶
type ProjectorParserBuilder struct {
// contains filtered or unexported fields
}
ProjectorParserBuilder contains the logic and data needed to create field selection parsers. Don't create instances of this type directly, use the NewProjectorParser function instead.
func NewProjectorParser ¶
func NewProjectorParser() *ProjectorParserBuilder
NewProjectorParser creates a builder that can then be used to configure and create field selector parsers.
func (*ProjectorParserBuilder) Build ¶
func (b *ProjectorParserBuilder) Build() (result *ProjectorParser, err error)
Build uses the configuration stored in the builder to create a new parser.
func (*ProjectorParserBuilder) SetLogger ¶
func (b *ProjectorParserBuilder) SetLogger(value *slog.Logger) *ProjectorParserBuilder
SetLogger sets the logger that the parser will use to write log messages. This is mandatory.
type Selector ¶
type Selector struct {
Terms []*Term
}
Selector represents an attribute-based filter expression as defined in section 5.2 of ETSI GS NFV-SOL 013.
type SelectorEvaluator ¶
type SelectorEvaluator struct {
// contains filtered or unexported fields
}
SelectorEvaluator knows how to evaluate filter expressions. Don't create instances of this type directly, use the NewSelectorEvaluator function instead.
type SelectorEvaluatorBuilder ¶
type SelectorEvaluatorBuilder struct {
// contains filtered or unexported fields
}
SelectorEvaluatorBuilder contains the logic and data needed to create filter expression evaluators. Don't create instances of this type directly, use the NewSelectorEvaluator function instead.
func NewSelectorEvaluator ¶
func NewSelectorEvaluator() *SelectorEvaluatorBuilder
NewSelectorEvaluator creates a builder that can then be used to configure and create expression filter evaluators.
func (*SelectorEvaluatorBuilder) Build ¶
func (b *SelectorEvaluatorBuilder) Build() (result *SelectorEvaluator, err error)
Build uses the configuration stored in the builder to create a new evaluator.
func (*SelectorEvaluatorBuilder) SetLogger ¶
func (b *SelectorEvaluatorBuilder) SetLogger(value *slog.Logger) *SelectorEvaluatorBuilder
SetLogger sets the logger that the evaluator will use to write log messages. This is mandatory.
func (*SelectorEvaluatorBuilder) SetPathEvaluator ¶
func (b *SelectorEvaluatorBuilder) SetPathEvaluator( value func(context.Context, Path, any) (any, error)) *SelectorEvaluatorBuilder
SetPathEvaluator sets the function that will be used to extract values of attributes from the object. This is mandatory.
The path evaluator function receives the attribute path and the object and should return the value of that attribute. For example, for a simple struct like this:
type Person struct { Name string Age int }
The path evaluator function could be like this:
func personPathEvaluator(ctx context.Context, path []string, object any) (result any, err error) { person, ok := object.(*Person) if !ok { err = fmt.Errorf("expected person, but got '%T'", object) return } if len(path) != 1 { err = fmt.Errorf("expected exactly one path segment, but got %d", len(path)) return } segment := path[0] switch segment { case "name": result = person.Name case "age": result = person.Age default: err = fmt.Errorf( "unknown attribute '%', valid attributes are 'name' and 'age'", segment, ) } return
The path evaluator function should return an error if the object isn't of the expected type, of if the path doesn't correspond to a valid attribute.
The path evaluator function should return nil if the path corresponds to a valid optional attribute that hasn't a value.
type SelectorParser ¶
type SelectorParser struct {
// contains filtered or unexported fields
}
SelectorParser knows how to parse filter expressions. Don't create instances of this type directly, use the NewSelectorParser function instead.
type SelectorParserBuilder ¶
type SelectorParserBuilder struct {
// contains filtered or unexported fields
}
SelectorParserBuilder contains the logic and data needed to create filter expression parsers. Don't create instances of this type directly, use the NewSelectorParser function instead.
func NewSelectorParser ¶
func NewSelectorParser() *SelectorParserBuilder
NewSelectorParser creates a builder that can then be used to configure and create expression filter // parsers. The builder can be reused to create multiple parsers with identical configuration.
func (*SelectorParserBuilder) Build ¶
func (b *SelectorParserBuilder) Build() (result *SelectorParser, err error)
Build uses the configuration stored in the builder to create a new parser.
func (*SelectorParserBuilder) SetLogger ¶
func (b *SelectorParserBuilder) SetLogger(value *slog.Logger) *SelectorParserBuilder
SetLogger sets the logger that the parser will use to write log messages. This is mandatory.
type Term ¶
type Term struct { // Operator is the operator that used to compare the attribute to the value. Operator Operator // Path is the path of the attribute. This will always contain at least one segment. Each // segment is the name of the attribute. For example in a complex object like this: // // { // "extensions": { // "user": "myuser", // "password": "mypassword" // } // } // // The path to the attribute containing the password will be: // // []string{ // "extensions", // "password", // } Path []string // Values is the list of values that the attribute will be compared to. It will contain // only one value for unary operators like `eq` or `neq`, and multiple values for // operators like `in` or `nin`. Values []any }
Term is each of the terms that compose a elector The selector will match an object when all the terms match it -in other words, terms are connected by the and logical directive.