Documentation ¶
Index ¶
- func IsImmutableAttributeError(err error) bool
- func IsUnknownAttribute(err error) bool
- func StructToMap(s interface{}) (map[string]interface{}, error)
- func UnknownAttribute(received, expected map[string]interface{}) error
- func ValidateImmutableAttribute(received, blacklist map[string]interface{}) error
- type ImmutableAttributeError
- type UnknownAttributeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsImmutableAttributeError ¶
IsImmutableAttributeError lets you check if an error is an ImmutableAttributeError.
func IsUnknownAttribute ¶
IsUnknownAttribute asserts UnknownAttributeError.
func StructToMap ¶
StructToMap is a helper method to convert an expected request data structure in the correctly formatted type to UnknownAttributes.
func UnknownAttribute ¶
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 ¶
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.