# README

Greenbone Logo

filter

import "github.com/greenbone/opensight-golang-libraries/pkg/query/filter"

Index

Variables

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

func AggregateMetricNames() []string

AggregateMetricNames returns a list of possible string values of AggregateMetric.

func CompareOperatorNames

func CompareOperatorNames() []string

CompareOperatorNames returns a list of possible string values of CompareOperator.

func ControlTypeNames

func ControlTypeNames() []string

ControlTypeNames returns a list of possible string values of ControlType.

func LogicOperatorNames

func LogicOperatorNames() []string

LogicOperatorNames returns a list of possible string values of LogicOperator.

func NewInvalidFilterFieldError

func NewInvalidFilterFieldError(format string, value ...any) error

func ValidateFilter

func ValidateFilter(request *Request, requestOptions []RequestOption) error

ValidateFilter validates the filter in the request

type AggregateMetric

AggregateMetric ENUM(

sum
min
max
avg

valueCount

)

type AggregateMetric string

const (
    // 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

func ParseAggregateMetric(name string) (AggregateMetric, error)

ParseAggregateMetric attempts to convert a string to a AggregateMetric.

func (AggregateMetric) IsValid

func (x AggregateMetric) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (AggregateMetric) MarshalText

func (x AggregateMetric) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (*AggregateMetric) Scan

func (x *AggregateMetric) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (AggregateMetric) String

func (x AggregateMetric) String() string

String implements the Stringer interface.

func (*AggregateMetric) UnmarshalText

func (x *AggregateMetric) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (AggregateMetric) Value

func (x AggregateMetric) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type CompareOperator

CompareOperator ENUM(

beginsWith
doesNotBeginWith
contains
doesNotContain

isNumberEqualTo
isEqualTo
isIpEqualTo
isStringEqualTo

isNotEqualTo
isNumberNotEqualTo
isIpNotEqualTo
isStringNotEqualTo

isGreaterThan
isGreaterThanOrEqualTo
isLessThan
isLessThanOrEqualTo
beforeDate
afterDate

exists

)

type CompareOperator string

const (
    // 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"
    // CompareOperatorIsNumberEqualTo is a CompareOperator of type isNumberEqualTo.
    CompareOperatorIsNumberEqualTo CompareOperator = "isNumberEqualTo"
    // CompareOperatorIsEqualTo is a CompareOperator of type isEqualTo.
    CompareOperatorIsEqualTo CompareOperator = "isEqualTo"
    // CompareOperatorIsIpEqualTo is a CompareOperator of type isIpEqualTo.
    CompareOperatorIsIpEqualTo CompareOperator = "isIpEqualTo"
    // CompareOperatorIsStringEqualTo is a CompareOperator of type isStringEqualTo.
    CompareOperatorIsStringEqualTo CompareOperator = "isStringEqualTo"
    // CompareOperatorIsNotEqualTo is a CompareOperator of type isNotEqualTo.
    CompareOperatorIsNotEqualTo CompareOperator = "isNotEqualTo"
    // CompareOperatorIsNumberNotEqualTo is a CompareOperator of type isNumberNotEqualTo.
    CompareOperatorIsNumberNotEqualTo CompareOperator = "isNumberNotEqualTo"
    // CompareOperatorIsIpNotEqualTo is a CompareOperator of type isIpNotEqualTo.
    CompareOperatorIsIpNotEqualTo CompareOperator = "isIpNotEqualTo"
    // CompareOperatorIsStringNotEqualTo is a CompareOperator of type isStringNotEqualTo.
    CompareOperatorIsStringNotEqualTo CompareOperator = "isStringNotEqualTo"
    // 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"
    // CompareOperatorExists is a CompareOperator of type exists.
    CompareOperatorExists CompareOperator = "exists"
)

func ParseCompareOperator

func ParseCompareOperator(name string) (CompareOperator, error)

ParseCompareOperator attempts to convert a string to a CompareOperator.

func (CompareOperator) IsValid

func (x CompareOperator) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (CompareOperator) MarshalText

func (x CompareOperator) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (*CompareOperator) Scan

func (x *CompareOperator) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (CompareOperator) String

func (x CompareOperator) String() string

String implements the Stringer interface.

func (*CompareOperator) UnmarshalText

func (x *CompareOperator) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (CompareOperator) Value

func (x CompareOperator) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type ControlType

ControlType ENUM(

enum
float
integer
string
dateTime
uuid
autocomplete

)

type ControlType string

const (
    // 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

func ParseControlType(name string) (ControlType, error)

ParseControlType attempts to convert a string to a ControlType.

func (ControlType) IsValid

func (x ControlType) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (ControlType) MarshalText

func (x ControlType) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (*ControlType) Scan

func (x *ControlType) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (ControlType) String

func (x ControlType) String() string

String implements the Stringer interface.

func (*ControlType) UnmarshalText

func (x *ControlType) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (ControlType) Value

func (x ControlType) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type InvalidFilterFieldError

type InvalidFilterFieldError struct {
    // contains filtered or unexported fields
}

func (*InvalidFilterFieldError) Error

func (i *InvalidFilterFieldError) Error() string

type LogicOperator

LogicOperator ENUM(

and
or

)

type LogicOperator string

const (
    // LogicOperatorAnd is a LogicOperator of type and.
    LogicOperatorAnd LogicOperator = "and"
    // LogicOperatorOr is a LogicOperator of type or.
    LogicOperatorOr LogicOperator = "or"
)

func ParseLogicOperator

func ParseLogicOperator(name string) (LogicOperator, error)

ParseLogicOperator attempts to convert a string to a LogicOperator.

func (LogicOperator) IsValid

func (x LogicOperator) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (LogicOperator) MarshalText

func (x LogicOperator) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (*LogicOperator) Scan

func (x *LogicOperator) Scan(value interface{}) (err error)

Scan implements the Scanner interface.

func (LogicOperator) String

func (x LogicOperator) String() string

String implements the Stringer interface.

func (*LogicOperator) UnmarshalText

func (x *LogicOperator) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

func (LogicOperator) Value

func (x LogicOperator) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type ReadableValue

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"`
}

type Request

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"`
}

type RequestField

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"`
    Operator CompareOperator `json:"operator" binding:"required"`
    // Value can be a list of values or a value
    Value any `json:"value" binding:"required"`
}

type RequestOption

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
}

type RequestOptionType

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"`
}

type UuidValidationError

type UuidValidationError struct {
    // contains filtered or unexported fields
}

func NewUuidValidationError

func NewUuidValidationError(format string, value ...any) *UuidValidationError

func (*UuidValidationError) Error

func (v *UuidValidationError) Error() string

type ValidationError

type ValidationError struct {
    // contains filtered or unexported fields
}

func NewValidationError

func NewValidationError(format string, value ...any) *ValidationError

func (*ValidationError) Error

func (v *ValidationError) Error() string

Generated by gomarkdoc

License

Copyright (C) 2022-2023 [Greenbone AG][Greenbone AG]

Licensed under the GNU General Public License v3.0 or later.

# Functions

AggregateMetricNames returns a list of possible string values of AggregateMetric.
CompareOperatorNames returns a list of possible string values of CompareOperator.
ControlTypeNames returns a list of possible string values of ControlType.
LogicOperatorNames returns a list of possible string values of LogicOperator.
No description provided by the author
No description provided by the author
No description provided by the author
ParseAggregateMetric attempts to convert a string to a AggregateMetric.
ParseCompareOperator attempts to convert a string to a CompareOperator.
ParseControlType attempts to convert a string to a ControlType.
ParseLogicOperator attempts to convert a string to a LogicOperator.
ValidateFilter validates the filter in the request.

# Constants

AggregateMetricAvg is a AggregateMetric of type avg.
AggregateMetricMax is a AggregateMetric of type max.
AggregateMetricMin is a AggregateMetric of type min.
AggregateMetricSum is a AggregateMetric of type sum.
AggregateMetricValueCount is a AggregateMetric of type valueCount.
CompareOperatorAfterDate is a CompareOperator of type afterDate.
CompareOperatorBeforeDate is a CompareOperator of type beforeDate.
CompareOperatorBeginsWith is a CompareOperator of type beginsWith.
CompareOperatorContains is a CompareOperator of type contains.
CompareOperatorDoesNotBeginWith is a CompareOperator of type doesNotBeginWith.
CompareOperatorDoesNotContain is a CompareOperator of type doesNotContain.
CompareOperatorExists is a CompareOperator of type exists.
CompareOperatorIsEqualTo is a CompareOperator of type isEqualTo.
CompareOperatorIsGreaterThan is a CompareOperator of type isGreaterThan.
CompareOperatorIsGreaterThanOrEqualTo is a CompareOperator of type isGreaterThanOrEqualTo.
CompareOperatorIsIpEqualTo is a CompareOperator of type isIpEqualTo.
CompareOperatorIsIpNotEqualTo is a CompareOperator of type isIpNotEqualTo.
CompareOperatorIsLessThan is a CompareOperator of type isLessThan.
CompareOperatorIsLessThanOrEqualTo is a CompareOperator of type isLessThanOrEqualTo.
CompareOperatorIsNotEqualTo is a CompareOperator of type isNotEqualTo.
CompareOperatorIsNumberEqualTo is a CompareOperator of type isNumberEqualTo.
CompareOperatorIsNumberNotEqualTo is a CompareOperator of type isNumberNotEqualTo.
CompareOperatorIsStringEqualTo is a CompareOperator of type isStringEqualTo.
CompareOperatorIsStringNotEqualTo is a CompareOperator of type isStringNotEqualTo.
ControlTypeAutocomplete is a ControlType of type autocomplete.
ControlTypeBool is a ControlType of type bool.
ControlTypeDateTime is a ControlType of type dateTime.
ControlTypeEnum is a ControlType of type enum.
ControlTypeFloat is a ControlType of type float.
ControlTypeInteger is a ControlType of type integer.
ControlTypeString is a ControlType of type string.
ControlTypeUuid is a ControlType of type uuid.
LogicOperatorAnd is a LogicOperator of type and.
LogicOperatorOr is a LogicOperator of type or.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
ReadableValue is a generic type that represents a human-readable value with a corresponding backend value.
Request is a struct representing a filter request.
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.
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.
RequestOptionType configures the type of control for a field in a request option.
No description provided by the author
No description provided by the author

# Type aliases

AggregateMetric ENUM( sum min max avg valueCount ) */.
CompareOperator ENUM( beginsWith doesNotBeginWith contains doesNotContain isNumberEqualTo isEqualTo isIpEqualTo isStringEqualTo isNotEqualTo isNumberNotEqualTo isIpNotEqualTo isStringNotEqualTo isGreaterThan isGreaterThanOrEqualTo isLessThan isLessThanOrEqualTo beforeDate afterDate exists ) */.
ControlType ENUM( bool enum float integer string dateTime uuid autocomplete ) */.
LogicOperator ENUM( and or ) */.