import "github.com/greenbone/opensight-golang-libraries/pkg/query/filter"- Variables
- func AggregateMetricNames() []string
- func CompareOperatorNames() []string
- func ControlTypeNames() []string
- func LogicOperatorNames() []string
- func NewInvalidFilterFieldError(format string, value ...any) error
- func ValidateFilter(request *Request, requestOptions []RequestOption) error
- type AggregateMetric
- func ParseAggregateMetric(name string) (AggregateMetric, error)
- func (x *AggregateMetric) AppendText(b []byte) ([]byte, error)
- func (x AggregateMetric) Cmp(other AggregateMetric) int
- func (x AggregateMetric) IsValid() bool
- func (x AggregateMetric) MarshalText() ([]byte, error)
- func (x *AggregateMetric) Scan(value interface{}) (err error)
- func (x AggregateMetric) String() string
- func (x *AggregateMetric) UnmarshalText(text []byte) error
- func (x AggregateMetric) Value() (driver.Value, error)
- type CompareOperator
- func ParseCompareOperator(name string) (CompareOperator, error)
- func (x *CompareOperator) AppendText(b []byte) ([]byte, error)
- func (x CompareOperator) Cmp(other CompareOperator) int
- func (x CompareOperator) IsValid() bool
- func (x CompareOperator) MarshalText() ([]byte, error)
- func (x *CompareOperator) Scan(value interface{}) (err error)
- func (x CompareOperator) String() string
- func (x *CompareOperator) UnmarshalText(text []byte) error
- func (x CompareOperator) Value() (driver.Value, error)
- type ControlType
- func ParseControlType(name string) (ControlType, error)
- func (x *ControlType) AppendText(b []byte) ([]byte, error)
- func (x ControlType) Cmp(other ControlType) int
- func (x ControlType) IsValid() bool
- func (x ControlType) MarshalText() ([]byte, error)
- func (x *ControlType) Scan(value interface{}) (err error)
- func (x ControlType) String() string
- func (x *ControlType) UnmarshalText(text []byte) error
- func (x ControlType) Value() (driver.Value, error)
- type InvalidFilterFieldError
- type LogicOperator
- func ParseLogicOperator(name string) (LogicOperator, error)
- func (x *LogicOperator) AppendText(b []byte) ([]byte, error)
- func (x LogicOperator) Cmp(other LogicOperator) int
- func (x LogicOperator) IsValid() bool
- func (x LogicOperator) MarshalText() ([]byte, error)
- func (x *LogicOperator) Scan(value interface{}) (err error)
- func (x LogicOperator) String() string
- func (x *LogicOperator) UnmarshalText(text []byte) error
- func (x LogicOperator) Value() (driver.Value, error)
- type ReadableValue
- type Request
- type RequestField
- type RequestOption
- type RequestOptionType
- type UuidValidationError
- type ValidationError
var ErrInvalidAggregateMetric = fmt.Errorf("not a valid AggregateMetric, try [%s]", strings.Join(_AggregateMetricNames, ", "))var ErrInvalidCompareOperator = fmt.Errorf("not a valid CompareOperator, try [%s]", strings.Join(_CompareOperatorNames, ", "))var ErrInvalidControlType = fmt.Errorf("not a valid ControlType, try [%s]", strings.Join(_ControlTypeNames, ", "))var ErrInvalidLogicOperator = fmt.Errorf("not a valid LogicOperator, try [%s]", strings.Join(_LogicOperatorNames, ", "))func AggregateMetricNames() []stringAggregateMetricNames returns a list of possible string values of AggregateMetric.
func CompareOperatorNames() []stringCompareOperatorNames returns a list of possible string values of CompareOperator.
func ControlTypeNames() []stringControlTypeNames returns a list of possible string values of ControlType.
func LogicOperatorNames() []stringLogicOperatorNames returns a list of possible string values of LogicOperator.
func NewInvalidFilterFieldError(format string, value ...any) errorfunc ValidateFilter(request *Request, requestOptions []RequestOption) errorValidateFilter validates the filter in the request
AggregateMetric ENUM(
sum
min
max
avg
valueCount
)
type AggregateMetric stringconst (
// AggregateMetricSum is a AggregateMetric of type sum.
AggregateMetricSum AggregateMetric = "sum"
// AggregateMetricMin is a AggregateMetric of type min.
AggregateMetricMin AggregateMetric = "min"
// AggregateMetricMax is a AggregateMetric of type max.
AggregateMetricMax AggregateMetric = "max"
// AggregateMetricAvg is a AggregateMetric of type avg.
AggregateMetricAvg AggregateMetric = "avg"
// AggregateMetricValueCount is a AggregateMetric of type valueCount.
AggregateMetricValueCount AggregateMetric = "valueCount"
)func ParseAggregateMetric(name string) (AggregateMetric, error)ParseAggregateMetric attempts to convert a string to a AggregateMetric.
func (x *AggregateMetric) AppendText(b []byte) ([]byte, error)AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.
Implementations must not retain b, nor mutate any bytes within b[:len(b)].
func (x AggregateMetric) Cmp(other AggregateMetric) intfunc (x AggregateMetric) IsValid() boolIsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (x AggregateMetric) MarshalText() ([]byte, error)MarshalText implements the text marshaller method.
func (x *AggregateMetric) Scan(value interface{}) (err error)Scan implements the Scanner interface.
func (x AggregateMetric) String() stringString implements the Stringer interface.
func (x *AggregateMetric) UnmarshalText(text []byte) errorUnmarshalText implements the text unmarshaller method.
func (x AggregateMetric) Value() (driver.Value, error)Value implements the driver Valuer interface.
CompareOperator ENUM(
beginsWith
doesNotBeginWith
contains
doesNotContain
textContains
isNumberEqualTo
isNumberNotEqualTo
isEqualTo
isNotEqualTo
isIpEqualTo
isIpNotEqualTo
isStringEqualTo
isStringNotEqualTo
isStringCaseInsensitiveEqualTo
isGreaterThan
isGreaterThanOrEqualTo
isLessThan
isLessThanOrEqualTo
beforeDate
afterDate
betweenDates
exists
isEqualToRating
isNotEqualToRating
isLessThanRating
isLessThanOrEqualToRating
isGreaterThanRating
isGreaterThanOrEqualToRating
)
type CompareOperator stringconst (
// CompareOperatorBeginsWith is a CompareOperator of type beginsWith.
CompareOperatorBeginsWith CompareOperator = "beginsWith"
// CompareOperatorDoesNotBeginWith is a CompareOperator of type doesNotBeginWith.
CompareOperatorDoesNotBeginWith CompareOperator = "doesNotBeginWith"
// CompareOperatorContains is a CompareOperator of type contains.
CompareOperatorContains CompareOperator = "contains"
// CompareOperatorDoesNotContain is a CompareOperator of type doesNotContain.
CompareOperatorDoesNotContain CompareOperator = "doesNotContain"
// CompareOperatorTextContains is a CompareOperator of type textContains.
CompareOperatorTextContains CompareOperator = "textContains"
// CompareOperatorIsNumberEqualTo is a CompareOperator of type isNumberEqualTo.
CompareOperatorIsNumberEqualTo CompareOperator = "isNumberEqualTo"
// CompareOperatorIsNumberNotEqualTo is a CompareOperator of type isNumberNotEqualTo.
CompareOperatorIsNumberNotEqualTo CompareOperator = "isNumberNotEqualTo"
// CompareOperatorIsEqualTo is a CompareOperator of type isEqualTo.
CompareOperatorIsEqualTo CompareOperator = "isEqualTo"
// CompareOperatorIsNotEqualTo is a CompareOperator of type isNotEqualTo.
CompareOperatorIsNotEqualTo CompareOperator = "isNotEqualTo"
// CompareOperatorIsIpEqualTo is a CompareOperator of type isIpEqualTo.
CompareOperatorIsIpEqualTo CompareOperator = "isIpEqualTo"
// CompareOperatorIsIpNotEqualTo is a CompareOperator of type isIpNotEqualTo.
CompareOperatorIsIpNotEqualTo CompareOperator = "isIpNotEqualTo"
// CompareOperatorIsStringEqualTo is a CompareOperator of type isStringEqualTo.
CompareOperatorIsStringEqualTo CompareOperator = "isStringEqualTo"
// CompareOperatorIsStringNotEqualTo is a CompareOperator of type isStringNotEqualTo.
CompareOperatorIsStringNotEqualTo CompareOperator = "isStringNotEqualTo"
// CompareOperatorIsStringCaseInsensitiveEqualTo is a CompareOperator of type isStringCaseInsensitiveEqualTo.
CompareOperatorIsStringCaseInsensitiveEqualTo CompareOperator = "isStringCaseInsensitiveEqualTo"
// CompareOperatorIsGreaterThan is a CompareOperator of type isGreaterThan.
CompareOperatorIsGreaterThan CompareOperator = "isGreaterThan"
// CompareOperatorIsGreaterThanOrEqualTo is a CompareOperator of type isGreaterThanOrEqualTo.
CompareOperatorIsGreaterThanOrEqualTo CompareOperator = "isGreaterThanOrEqualTo"
// CompareOperatorIsLessThan is a CompareOperator of type isLessThan.
CompareOperatorIsLessThan CompareOperator = "isLessThan"
// CompareOperatorIsLessThanOrEqualTo is a CompareOperator of type isLessThanOrEqualTo.
CompareOperatorIsLessThanOrEqualTo CompareOperator = "isLessThanOrEqualTo"
// CompareOperatorBeforeDate is a CompareOperator of type beforeDate.
CompareOperatorBeforeDate CompareOperator = "beforeDate"
// CompareOperatorAfterDate is a CompareOperator of type afterDate.
CompareOperatorAfterDate CompareOperator = "afterDate"
// CompareOperatorBetweenDates is a CompareOperator of type betweenDates.
CompareOperatorBetweenDates CompareOperator = "betweenDates"
// CompareOperatorExists is a CompareOperator of type exists.
CompareOperatorExists CompareOperator = "exists"
// CompareOperatorIsEqualToRating is a CompareOperator of type isEqualToRating.
CompareOperatorIsEqualToRating CompareOperator = "isEqualToRating"
// CompareOperatorIsNotEqualToRating is a CompareOperator of type isNotEqualToRating.
CompareOperatorIsNotEqualToRating CompareOperator = "isNotEqualToRating"
// CompareOperatorIsLessThanRating is a CompareOperator of type isLessThanRating.
CompareOperatorIsLessThanRating CompareOperator = "isLessThanRating"
// CompareOperatorIsLessThanOrEqualToRating is a CompareOperator of type isLessThanOrEqualToRating.
CompareOperatorIsLessThanOrEqualToRating CompareOperator = "isLessThanOrEqualToRating"
// CompareOperatorIsGreaterThanRating is a CompareOperator of type isGreaterThanRating.
CompareOperatorIsGreaterThanRating CompareOperator = "isGreaterThanRating"
// CompareOperatorIsGreaterThanOrEqualToRating is a CompareOperator of type isGreaterThanOrEqualToRating.
CompareOperatorIsGreaterThanOrEqualToRating CompareOperator = "isGreaterThanOrEqualToRating"
)func ParseCompareOperator(name string) (CompareOperator, error)ParseCompareOperator attempts to convert a string to a CompareOperator.
func (x *CompareOperator) AppendText(b []byte) ([]byte, error)AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.
Implementations must not retain b, nor mutate any bytes within b[:len(b)].
func (x CompareOperator) Cmp(other CompareOperator) intfunc (x CompareOperator) IsValid() boolIsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (x CompareOperator) MarshalText() ([]byte, error)MarshalText implements the text marshaller method.
func (x *CompareOperator) Scan(value interface{}) (err error)Scan implements the Scanner interface.
func (x CompareOperator) String() stringString implements the Stringer interface.
func (x *CompareOperator) UnmarshalText(text []byte) errorUnmarshalText implements the text unmarshaller method.
func (x CompareOperator) Value() (driver.Value, error)Value implements the driver Valuer interface.
ControlType ENUM(
bool
enum
float
integer
string
dateTime
uuid
autocomplete
)
type ControlType stringconst (
// ControlTypeBool is a ControlType of type bool.
ControlTypeBool ControlType = "bool"
// ControlTypeEnum is a ControlType of type enum.
ControlTypeEnum ControlType = "enum"
// ControlTypeFloat is a ControlType of type float.
ControlTypeFloat ControlType = "float"
// ControlTypeInteger is a ControlType of type integer.
ControlTypeInteger ControlType = "integer"
// ControlTypeString is a ControlType of type string.
ControlTypeString ControlType = "string"
// ControlTypeDateTime is a ControlType of type dateTime.
ControlTypeDateTime ControlType = "dateTime"
// ControlTypeUuid is a ControlType of type uuid.
ControlTypeUuid ControlType = "uuid"
// ControlTypeAutocomplete is a ControlType of type autocomplete.
ControlTypeAutocomplete ControlType = "autocomplete"
)func ParseControlType(name string) (ControlType, error)ParseControlType attempts to convert a string to a ControlType.
func (x *ControlType) AppendText(b []byte) ([]byte, error)AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.
Implementations must not retain b, nor mutate any bytes within b[:len(b)].
func (x ControlType) Cmp(other ControlType) intfunc (x ControlType) IsValid() boolIsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (x ControlType) MarshalText() ([]byte, error)MarshalText implements the text marshaller method.
func (x *ControlType) Scan(value interface{}) (err error)Scan implements the Scanner interface.
func (x ControlType) String() stringString implements the Stringer interface.
func (x *ControlType) UnmarshalText(text []byte) errorUnmarshalText implements the text unmarshaller method.
func (x ControlType) Value() (driver.Value, error)Value implements the driver Valuer interface.
type InvalidFilterFieldError struct {
// contains filtered or unexported fields
}func (i *InvalidFilterFieldError) Error() stringLogicOperator ENUM(
and
or
)
type LogicOperator stringconst (
// LogicOperatorAnd is a LogicOperator of type and.
LogicOperatorAnd LogicOperator = "and"
// LogicOperatorOr is a LogicOperator of type or.
LogicOperatorOr LogicOperator = "or"
)func ParseLogicOperator(name string) (LogicOperator, error)ParseLogicOperator attempts to convert a string to a LogicOperator.
func (x *LogicOperator) AppendText(b []byte) ([]byte, error)AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.
Implementations must not retain b, nor mutate any bytes within b[:len(b)].
func (x LogicOperator) Cmp(other LogicOperator) intfunc (x LogicOperator) IsValid() boolIsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (x LogicOperator) MarshalText() ([]byte, error)MarshalText implements the text marshaller method.
func (x *LogicOperator) Scan(value interface{}) (err error)Scan implements the Scanner interface.
func (x LogicOperator) String() stringString implements the Stringer interface.
func (x *LogicOperator) UnmarshalText(text []byte) errorUnmarshalText implements the text unmarshaller method.
func (x LogicOperator) Value() (driver.Value, error)Value implements the driver Valuer interface.
ReadableValue is a generic type that represents a human-readable value with a corresponding backend value. It has two fields: `Label` (the human-readable form of the value) and `Value` (the value for the backend).
type ReadableValue[T any] struct {
// Label is the human-readable form of the value
Label string `json:"label"`
// Value is the value for the backend
Value T `json:"value"`
}func NewReadableValue[T any](label string, value T) ReadableValue[T]NewReadableValue is a constructor faction that helps with auto detection of value type while creating ReadableValue.
func SortedReadableValues[T any](values ...ReadableValue[T]) []ReadableValue[T]SortedReadableValues creates a sorted slice of ReadableValues.
func (x ReadableValue[T]) Cmp(other ReadableValue[T]) intCmp allows comparing two ReadableValues. It first compares values (if they are comparable in any way) and then it compares labels.
Request is a struct representing a filter request. Operator is the logic operator used for the request. Fields is a slice of RequestField, representing the fields to be used for the filtering.
type Request struct {
Operator LogicOperator `json:"operator" binding:"required"`
Fields []RequestField `json:"fields" binding:"dive"`
}RequestField represents a field in a request Field Name: The name of the field Field Keys: Sequence of keys of a nested key structure - only used for fields with a nested structure. Example: Tag -> Name: ABC (which would be represented as []string{"Tag", "Name: ABC"} ) Field Operator: The comparison operator for the field Field Value: The value of the field, which can be a list of values or a single value
type RequestField struct {
Name string `json:"name" binding:"required"`
Keys []string `json:"keys,omitempty"`
Operator CompareOperator `json:"operator" binding:"required"`
// Value can be a list of values or a value
Value any `json:"value" binding:"required"`
}RequestOption configures a field for validation
Name: The name of the option Control: The type of control for the option Operators: The list of comparison operators for the option Values: The possible values for the option MultiSelect: Indicates whether the option supports multiple selections
type RequestOption struct {
Name ReadableValue[string]
Control RequestOptionType
Operators []ReadableValue[CompareOperator]
Values []string
MultiSelect bool
}RequestOptionType configures the type of control for a field in a request option.
type RequestOptionType struct {
Type ControlType `json:"type" enums:"string,float,integer,enum,bool"`
}type UuidValidationError struct {
// contains filtered or unexported fields
}func NewUuidValidationError(format string, value ...any) *UuidValidationErrorfunc (v *UuidValidationError) Error() stringtype ValidationError struct {
// contains filtered or unexported fields
}func NewValidationError(format string, value ...any) *ValidationErrorfunc (v *ValidationError) Error() stringGenerated by gomarkdoc
Copyright (C) 2022-2023 [Greenbone AG][Greenbone AG]
Licensed under the GNU General Public License v3.0 or later.
