validator

package
v0.0.0-...-dec35dd Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 5 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CanUseMarkerProvider

type CanUseMarkerProvider func(v interface{}) bool

type Option

type Option func(o *Options)

Option defines validator option

func WithCanUseMarkerProvider

func WithCanUseMarkerProvider(provider CanUseMarkerProvider) Option

WithCanUseMarkerProvider creates with marker provider option

func WithDB

func WithDB(db *sql.DB) Option

WithDB create with db validation option

func WithLocation

func WithLocation(location string) Option

WithLocation creates with location option

func WithRefCheck

func WithRefCheck(flag bool) Option

WithRefCheck return with ref check option

func WithSetMarker

func WithSetMarker(f bool) Option

WithShallow creates with shallow option

func WithShallow

func WithShallow(f bool) Option

WithShallow creates with shallow option

func WithUnique

func WithUnique(flag bool) Option

WithUnique returns with unique check

func WithValidation

func WithValidation(v *Validation) Option

WithValidation creates with Validation option

type Options

type Options struct {
	WithShallow          bool
	WithSetMarker        bool
	WithDB               *sql.DB
	WithUnique           bool
	WithRef              bool
	Location             string
	CanUseMarkerProvider CanUseMarkerProvider
	WithValidation       *Validation
}

Options defins validator options

func (*Options) Apply

func (o *Options) Apply(opts []Option)

type Service

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

func New

func New(validator Validator) *Service

func (*Service) Validate

func (s *Service) Validate(ctx context.Context, any interface{}, options ...Option) (*Validation, error)

type Validation

type Validation struct {
	Violations Violations `json:",omitempty"`
	Failed     bool       `json:",omitempty"`
}

Validation represents validation

func NewValidation

func NewValidation() *Validation

NewValidation returns a validation

func (*Validation) AddViolation

func (v *Validation) AddViolation(location, field string, value interface{}, check string, msg string)

AddViolation adds violation

func (*Validation) Append

func (v *Validation) Append(location, field string, value interface{}, check string, msg string)

Append appends violation

type Validator

type Validator interface {
	Validate(ctx context.Context, any interface{}, options ...Option) (*Validation, error)
}

type Violation

type Violation struct {
	Location string      `json:",omitempty"`
	Field    string      `json:",omitempty"`
	Value    interface{} `json:",omitempty"`
	Message  string      `json:",omitempty"`
	Check    string      `json:",omitempty"`
}

Violation represent validation violation

type Violations

type Violations []*Violation

func (Violations) Sort

func (v Violations) Sort()

Sort sorts violations

Jump to

Keyboard shortcuts

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