fender

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 5 Imported by: 1

README

fender

a piece of rope or a tyre that protects the side of a boat from knocks

Usage

err := fender.NewFields().
	Add("firstName", fender.RequiredString(u.FirstName)).
	Add("lastName", fender.RequiredString(u.LastName)).
	Add("age", fender.MinInt(u.Age, 0), fender.MaxInt(u.Age, 130)).
	Add("email", fender.Email(u.Email, false)).
	Add("street", fender.RequiredString(u.Street)).
	Add("city", fender.RequiredString(u.City)).
	Add("planet", fender.RequiredString(u.Planet)).
	Add("phone", fender.RequiredString(u.Phone)).
	AllError()
if err != nil {
	panic(err)
}

Rules

List of built-in fending rules:

  • email
  • enum
  • max
  • min
  • required
  • regex
  • size

Benchmarks

goos: darwin
goarch: amd64
cpu: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
BenchmarkFender/valid-12           	     1496362	       699 ns/op
BenchmarkFender/invalid-12               1176252 	       975 ns/op
BenchmarkPlayground/valid-12           	   42367	     25967 ns/op
BenchmarkPlayground/invalid-12         	   37567	     28034 ns/op

References & alternatives

How to Contribute

Make a pull request...

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Err = errors.New("validation error")

Functions

func All added in v0.3.0

func All(fields ...FendField) error

func AllFirst added in v0.3.0

func AllFirst(fields ...FendField) error

func First added in v0.3.0

func First(fields ...FendField) error

Types

type Error added in v0.3.0

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

Error type

func NewError added in v0.3.0

func NewError(fields Errors) *Error

NewError constructor

func (*Error) Error added in v0.3.0

func (e *Error) Error() string

Error interface

func (*Error) Errors added in v0.3.0

func (e *Error) Errors() Errors

func (*Error) First added in v0.3.0

func (e *Error) First() error

func (*Error) Is added in v0.3.0

func (e *Error) Is(err error) bool

Is interface

type Errors added in v0.3.0

type Errors map[string][]*rule.Error

Errors type

func (Errors) String added in v0.3.0

func (m Errors) String() string

String returns the string representation

type FendField added in v0.3.0

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

func Field added in v0.3.0

func Field(name string, fends ...fend.Fend) FendField

type FendFields added in v0.3.2

type FendFields []FendField

func (FendFields) Add added in v0.3.2

func (f FendFields) Add(fields ...FendField) FendFields

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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