validator

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	CheckKidUnique  = CheckKid("unique")
	CheckKidRefKey  = CheckKid("refKey")
	CheckKidNotNull = CheckKid("notnull")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check struct {
	SQL        string
	Field      *xunsafe.Field
	ErrorMsg   string
	CheckType  reflect.Type
	CheckField *xunsafe.Field
}

type CheckKid

type CheckKid string

type Error

type Error struct {
	Violation []*Violation
}

func (*Error) AppendNotNull

func (e *Error) AppendNotNull(path *Path, field, msg string)

func (*Error) AppendRef

func (e *Error) AppendRef(path *Path, field string, value interface{}, msg string)

func (*Error) AppendUnique

func (e *Error) AppendUnique(path *Path, field string, value interface{}, msg string)

func (*Error) Error

func (e *Error) Error() string

type Option

type Option func(c *Options)

func WithNotNull

func WithNotNull(flag bool) Option

func WithPresence

func WithPresence() Option

func WithRef

func WithRef(flag bool) Option

func WithUnique

func WithUnique(flag bool) Option

option.PresenceProvider{}

type Options

type Options struct {
	CheckNotNull     bool
	CheckUnique      bool
	CheckRef         bool
	PresenceProvider *option.PresenceProvider
}

func NewOptions

func NewOptions() *Options

func (*Options) IsFieldSet

func (o *Options) IsFieldSet(ptr unsafe.Pointer, index int) bool

type Path

type Path struct {
	Elements []string
	IsSlice  bool
}

func (*Path) AppendField

func (p *Path) AppendField(field string) *Path

func (*Path) AppendIndex

func (p *Path) AppendIndex(index int) *Path

func (*Path) String

func (p *Path) String() string

type Service

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

func New

func New() *Service

New creates a new validation service

func (*Service) Validate

func (s *Service) Validate(ctx context.Context, db *sql.DB, any interface{}, opts ...Option) error

type Validation

type Validation struct {
	Type   reflect.Type
	Unique []*Check
	RefKey []*Check
	NoNull []*Check
	// contains filtered or unexported fields
}

func NewValidation

func NewValidation(p reflect.Type, presence *option.PresenceProvider) (*Validation, error)

type Violation

type Violation struct {
	Path    string
	Field   string
	Value   interface{}
	Message string
	Reason  string
}

Jump to

Keyboard shortcuts

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