validation

package
v0.67.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 6 Imported by: 6

Documentation

Overview

Package validation provides primitives for validating proto messages and gRPC requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewError

func NewError(fieldViolations []*errdetails.BadRequest_FieldViolation) error

NewError creates a new validation error from the provided field violations.

Types

type Error

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

Error represents a message validation error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) GRPCStatus

func (e *Error) GRPCStatus() *status.Status

GRPCStatus converts the validation error to a gRPC status with code INVALID_ARGUMENT.

type MessageValidator

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

MessageValidator provides primitives for validating the fields of a message.

func (*MessageValidator) AddFieldError

func (m *MessageValidator) AddFieldError(field string, err error)

AddFieldError adds a field violation from the provided error. If the provided error is a validation.Error, the individual field violations from the provided error are added.

func (*MessageValidator) AddFieldViolation

func (m *MessageValidator) AddFieldViolation(field, description string, formatArgs ...interface{})

AddFieldViolation adds a field violation to the message validator.

func (*MessageValidator) Err

func (m *MessageValidator) Err() error

Err returns the validator's current validation error, or nil if no field validations have been registered.

func (*MessageValidator) SetParentField

func (m *MessageValidator) SetParentField(parentField string)

SetParentField sets a parent field which will be prepended to all the subsequently added violations.

Jump to

Keyboard shortcuts

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