fields

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATE          = "state"
	SIZE_CACHE     = "sizeCache"
	UNKNOWN_FIELDS = "unknownFields"
)

Protobuf fields generated by the protoc compiler

Variables

View Source
var (
	MissingProtobufTagError         = "missing protobuf tag: %s"
	MissingProtobufNameError        = "missing protobuf name: %s"
	NilStructFieldsValidationsError = errors.New("nil struct fields validations")
	NilDataError                    = errors.New("nil data")
	NilStructFieldsToValidateError  = errors.New("nil struct fields to validate")
	FieldNotFoundError              = errors.New("field not found")
	InvalidBirthdateError           = errors.New("invalid birthdate")
	InvalidMailAddressError         = errors.New("invalid mail address")
	EmptyStringFieldError           = errors.New("string field is empty")
)

Functions

func ValidMailAddress

func ValidMailAddress(address string) (string, error)

ValidMailAddress checks if the mail address is valid

Types

type StructFieldsToValidate

type StructFieldsToValidate struct {
	Fields                       map[string]string // Key is the field name and value is the name used in the validation error
	NestedStructFieldsToValidate map[string]*StructFieldsToValidate
}

StructFieldsToValidate is a map of fields to validate from a struct

func CreateGRPCStructFieldsToValidate

func CreateGRPCStructFieldsToValidate(exampleStruct interface{}, mode *commonflag.ModeFlag) (
	*StructFieldsToValidate,
	error,
)

CreateGRPCStructFieldsToValidate creates the fields to validate from a gRPC struct

type StructFieldsValidations

type StructFieldsValidations struct {
	FailedFieldsValidations *map[string][]error
	NestedFieldsValidations *map[string]*StructFieldsValidations
}

StructFieldsValidations is a struct that holds the error messages for failed validations of the fields of a struct

func NewStructFieldsValidations

func NewStructFieldsValidations() *StructFieldsValidations

NewStructFieldsValidations creates a new StructFieldsValidations struct

func ValidateNilFields

func ValidateNilFields(
	data interface{},
	structFieldsToValidate *StructFieldsToValidate,
) (structFieldsValidations *StructFieldsValidations, err error)

ValidateNilFields validates if the fields are not nil

func (*StructFieldsValidations) AddFailedFieldValidationError

func (s *StructFieldsValidations) AddFailedFieldValidationError(validationName string, validationError error)

AddFailedFieldValidationError adds a failed field validation error to the struct

func (*StructFieldsValidations) FailedValidationsMessage

func (s *StructFieldsValidations) FailedValidationsMessage(level int) *string

FailedValidationsMessage returns a formatted error message for StructFieldsValidations

func (*StructFieldsValidations) GetLevelPadding

func (s *StructFieldsValidations) GetLevelPadding(level int) string

GetLevelPadding returns the padding for the level

func (*StructFieldsValidations) HasFailed

func (s *StructFieldsValidations) HasFailed() bool

HasFailed returns true if there are failed validations

func (*StructFieldsValidations) SetNestedFieldsValidations

func (s *StructFieldsValidations) SetNestedFieldsValidations(
	validationName string,
	nestedStructFieldsValidations *StructFieldsValidations,
)

SetNestedFieldsValidations sets the nested struct fields validations to the struct

func (*StructFieldsValidations) String

func (s *StructFieldsValidations) String() string

String returns a formatted error message f

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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