rule

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKind   = errors.New("is invalid kind")
	ErrInvalidBool   = errors.New("is invalid bool")
	ErrInvalidNumber = errors.New("is invalid number")
)
View Source
var ErrAddOperationTypeError = errors.New("add operation only applicable to array")
View Source
var ErrMaxRuleViolation = errors.New("value greater then specified")
View Source
var ErrOperationsNotAllowed = errors.New("operations are not allowed")

Functions

This section is empty.

Types

type AllowedOperationsRule

type AllowedOperationsRule struct {
	Operations []operation.Operation
}

AllowedOperationsRule defines witch patch operations are allowed for the field.

func (*AllowedOperationsRule) NewInheritInstance

func (a *AllowedOperationsRule) NewInheritInstance(_ string, _ reflect.Kind, _ interface{}) (Rule, error)

NewInheritInstance instantiate new rule instance based on given rule.

func (*AllowedOperationsRule) NewInstance

func (a *AllowedOperationsRule) NewInstance(
	path string, _ reflect.Kind, _ interface{}, value string,
) (Rule, error)

NewInstance instantiate new rule instance for field.

func (AllowedOperationsRule) Validate

func (a AllowedOperationsRule) Validate(operationSpec operation.Spec) error

Validate applies rule on given patch operation specification.

type DisallowRule

type DisallowRule struct {
	Disallow bool
}

DisallowRule defines if operations on field are disallowed.

func (*DisallowRule) NewInheritInstance

func (d *DisallowRule) NewInheritInstance(_ string, _ reflect.Kind, _ interface{}) (Rule, error)

NewInheritInstance instantiate new rule instance based on given rule.

func (*DisallowRule) NewInstance

func (d *DisallowRule) NewInstance(path string, _ reflect.Kind, instance interface{}, value string) (Rule, error)

NewInstance instantiate new rule instance for field.

func (DisallowRule) Validate

func (d DisallowRule) Validate(operationSpec operation.Spec) error

Validate applies rule on given patch operation specification.

type DisallowedOperationsRule

type DisallowedOperationsRule struct {
	Operations []operation.Operation
}

DisallowedOperationsRule defines witch patch operations are disallowed for the field.

func (*DisallowedOperationsRule) NewInheritInstance

func (d *DisallowedOperationsRule) NewInheritInstance(_ string, _ reflect.Kind, _ interface{}) (Rule, error)

NewInheritInstance instantiate new rule instance based on given rule.

func (*DisallowedOperationsRule) NewInstance

func (d *DisallowedOperationsRule) NewInstance(
	path string, _ reflect.Kind, _ interface{}, value string,
) (Rule, error)

NewInstance instantiate new rule instance for field.

func (DisallowedOperationsRule) Validate

func (d DisallowedOperationsRule) Validate(operationSpec operation.Spec) error

Validate applies rule on given patch operation specification.

type ExpressionNotMatchError

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

ExpressionNotMatchError indicate that given value not match expression.

func (ExpressionNotMatchError) Error

func (e ExpressionNotMatchError) Error() string

type ExpressionRule

type ExpressionRule struct {
	Expression string
	Regex      regexp.Regexp
}

ExpressionRule defines expression that needs to be matched by value. Anything is printed to string before e.g. int will be a number as string.

func (*ExpressionRule) NewInheritInstance

func (e *ExpressionRule) NewInheritInstance(path string, _ reflect.Kind, instance interface{}) (Rule, error)

NewInheritInstance instantiate new rule instance based on given rule.

func (*ExpressionRule) NewInstance

func (e *ExpressionRule) NewInstance(path string, _ reflect.Kind, instance interface{}, value string) (Rule, error)

NewInstance instantiate new rule instance for field.

func (ExpressionRule) Validate

func (e ExpressionRule) Validate(operationSpec operation.Spec) error

Validate applies rule on given patch operation specification.

type GreaterThenError

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

GreaterThenError indicate that a value is greater then the reference.

func (GreaterThenError) Error

func (g GreaterThenError) Error() string

type LessThenError

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

LessThenError indicate that a value is less then the reference.

func (LessThenError) Error

func (l LessThenError) Error() string

type MatchingKindRule

type MatchingKindRule struct {
	Instance interface{}
	Path     string
}

MatchingKindRule is a default rule that is applied to all fields. This rules checks for type and name matches to prevent input for unknown fields or to violate types.

func (*MatchingKindRule) NewInheritInstance

func (m *MatchingKindRule) NewInheritInstance(path string, _ reflect.Kind, instance interface{}) (Rule, error)

NewInheritInstance instantiate new rule instance based on given rule.

func (*MatchingKindRule) NewInstance

func (m *MatchingKindRule) NewInstance(path string, _ reflect.Kind, instance interface{}, _ string) (Rule, error)

UseValue instantiate new rule instance for field.

func (MatchingKindRule) Validate

func (m MatchingKindRule) Validate(operationSpec operation.Spec) error

Validate applies rule on given patch operation specification.

type MatchingOperationToKindRule added in v1.3.1

type MatchingOperationToKindRule struct {
	Kind reflect.Kind
}

MatchingOperationToKindRule is a default rule that is applied to all fields. This rules if operation is applyable to kind.

func (*MatchingOperationToKindRule) NewInheritInstance added in v1.3.1

func (m *MatchingOperationToKindRule) NewInheritInstance(_ string, kind reflect.Kind, _ interface{}) (Rule, error)

NewInheritInstance instantiate new rule instance based on given rule.

func (*MatchingOperationToKindRule) NewInstance added in v1.3.1

func (m *MatchingOperationToKindRule) NewInstance(_ string, kind reflect.Kind, _ interface{}, _ string) (Rule, error)

UseValue instantiate new rule instance for field.

func (MatchingOperationToKindRule) Validate added in v1.3.1

func (m MatchingOperationToKindRule) Validate(operationSpec operation.Spec) error

Validate applies rule on given patch operation specification.

type MaxRule

type MaxRule struct {
	Max float64
}

MaxRule defines the maximum size/value:

  • Applies on len for Array, Chan, Map, Slice and String.
  • Applies on value for any numeric type.

func (*MaxRule) NewInheritInstance

func (m *MaxRule) NewInheritInstance(_ string, _ reflect.Kind, _ interface{}) (Rule, error)

NewInheritInstance instantiate new rule instance based on given rule.

func (*MaxRule) NewInstance

func (m *MaxRule) NewInstance(path string, _ reflect.Kind, _ interface{}, value string) (Rule, error)

NewInstance instantiate new rule instance for field.

func (MaxRule) Validate

func (m MaxRule) Validate(operationSpec operation.Spec) error

Validate applies rule on given patch operation specification.

type MinRule

type MinRule struct {
	Min float64
}

MinRule defines the minimum size/value:

  • Applies on len for Array, Chan, Map, Slice and String.
  • Applies on value for any numeric type.

func (*MinRule) NewInheritInstance

func (m *MinRule) NewInheritInstance(_ string, _ reflect.Kind, _ interface{}) (Rule, error)

NewInheritInstance instantiate new rule instance based on given rule.

func (*MinRule) NewInstance

func (m *MinRule) NewInstance(path string, _ reflect.Kind, _ interface{}, value string) (Rule, error)

NewInstance instantiate new rule instance for field.

func (MinRule) Validate

func (m MinRule) Validate(operationSpec operation.Spec) error

Validate applies rule on given patch operation specification.

type OperationNotAllowedError

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

OperationNotAllowedError indicate that a given JSON patch operation is not allowed.

func (OperationNotAllowedError) Error

func (o OperationNotAllowedError) Error() string

type Rule

type Rule interface {
	NewInstance(patch string, kind reflect.Kind, instance interface{}, value string) (Rule, error)
	NewInheritInstance(patch string, kind reflect.Kind, instance interface{}) (Rule, error)
	Validate(operationSpec operation.Spec) error
}

Rule defines the interface for a patch operation rule.

type TypeMismatchError

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

TypeMismatchError indicate that a given type not match a reference.

func (TypeMismatchError) Error

func (t TypeMismatchError) Error() string

type UnknownFieldError

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

UnknownFieldError indicate that a field is not known.

func (UnknownFieldError) Error

func (u UnknownFieldError) Error() string

Jump to

Keyboard shortcuts

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