validator

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsImmutableAttributeError

func IsImmutableAttributeError(err error) bool

IsImmutableAttributeError lets you check if an error is an ImmutableAttributeError.

func IsUnknownAttribute

func IsUnknownAttribute(err error) bool

IsUnknownAttribute asserts UnknownAttributeError.

func StructToMap

func StructToMap(s interface{}) (map[string]interface{}, error)

StructToMap is a helper method to convert an expected request data structure in the correctly formatted type to UnknownAttributes.

func UnknownAttribute

func UnknownAttribute(received, expected map[string]interface{}) error

UnknownAttribute takes an arbitrary map and a map obtaining some expected structure. The first argument might represent an incoming request of some microservice. The second argument should then represent the datastructure of the associated request as it is expected to be provided. In case received contains fields which are not available in expected, an UnknownAttributeError is returned.

func ValidateImmutableAttribute

func ValidateImmutableAttribute(received, blacklist map[string]interface{}) error

ValidateImmutableAttribute takes an arbitrary map and a map obtaining some expected structure. The first argument might represent an incoming request of some microservice. The second argument should contain a datastructure representing only the attributes that are allowed to be mutated. If the first map contains fields which are not in the whitelist expected, an ImmutableAttributeError is returned.

Types

type ImmutableAttributeError

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

ImmutableAttributeError indicates a data structure is invalid because it contains fields that are immutable.

func ToImmutableAttributeError

func ToImmutableAttributeError(err error) ImmutableAttributeError

ToImmutableAttributeError tries to cast a given error into a ImmutableAttributeError and returns it. ToImmutableAttributeError will panic in case the underlying error is not of type ToImmutableAttributeError. Use IsImmutableAttributeError before calling ToImmutableAttributeError.

func (ImmutableAttributeError) Attribute

func (e ImmutableAttributeError) Attribute() string

Attribute returns the attribute that is causing the immutable attribute error.

func (ImmutableAttributeError) Error

func (e ImmutableAttributeError) Error() string

Error returns ImmutableAttributeError's message. This way ImmutableAttributeError implements the error interface.

type UnknownAttributeError

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

UnknownAttributeError indicates there was an error due to unknown attributes within validated data structures.

func ToUnknownAttribute

func ToUnknownAttribute(err error) UnknownAttributeError

ToUnknownAttribute tries asserts the given error to UnknownAttributeError and returns it. ToUnknownAttribute panics in case the underlying error is not of type UnknownAttributeError. Therefore IsUnknownAttribute should always be used to verify the safe execution of ToUnknownAttribute beforehand.

func (UnknownAttributeError) Attribute

func (e UnknownAttributeError) Attribute() string

Attribute returns the detected unknown attribute.

func (UnknownAttributeError) Error

func (e UnknownAttributeError) Error() string

Error returns the actual error message of the UnknownAttributeError to implement the error interface.

Jump to

Keyboard shortcuts

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