validator

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: Apache-2.0 Imports: 12 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
	Required   bool
}

type CheckKid

type CheckKid string

type Checks added in v0.5.1

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

func NewChecks added in v0.5.1

func NewChecks(p reflect.Type, presence *option.SetMarker) (*Checks, error)

type Option

type Option func(c *Options)

func WithLocation added in v0.5.2

func WithLocation(location string) Option

WithLocation creates with location option

func WithRef

func WithRef(flag bool) Option

WithRef with ref key option

func WithRequired added in v0.5.1

func WithRequired(flag bool) Option

WithRequired with required optio

func WithSetMarker added in v0.7.1

func WithSetMarker() Option

func WithUnique

func WithUnique(flag bool) Option

WithUnique with unique option

type Options

type Options struct {
	Required    bool
	CheckUnique bool
	CheckRef    bool
	Location    string
	SetMarker   *option.SetMarker
}

func NewOptions

func NewOptions() *Options

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) (*Validation, error)

type Validation

type Validation struct {
	Violations []*Violation
	Failed     bool
}

func (*Validation) AppendNotNull added in v0.5.1

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

func (*Validation) AppendRef added in v0.5.1

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

func (*Validation) AppendUnique added in v0.5.1

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

func (*Validation) Error added in v0.5.1

func (e *Validation) Error() string

func (*Validation) String added in v0.5.1

func (e *Validation) String() string

type Violation

type Violation struct {
	Location string
	Field    string
	Value    interface{}
	Message  string
	Check    string
}

Jump to

Keyboard shortcuts

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