echovalidate

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

参数自动绑定和参数校验在web项目开发中,是一项非常重要的功能。在保证数据安全完整性的同时,还可以极大的提升开发速度

echovalidate包,重写了echo框架的binder,将参数绑定和验证合为一步完成。通过Tag标签value自动识别报错信息。

安装

go get github.com/jeffcail/echovalidate

使用

1.
e.Validator = echovalidate.NewCustomerValidator()
2. 示例
type User struct {
    Name  string `json:"name" form:"name" query:"name" validate:"required" value:"名称必填"`
    Email string `json:"email" form:"email" query:"email" validate:"required,email" value:"邮箱必填,邮箱格式不正确"`
    Id    int64  `json:"id" form:"id" query:"id" validate:"required,number,gt=0,lt=100" value:"必填,为数值型,必须大于1小于100"`
}
u := new(User)

echovalidate.NewBinder().Binder(echo.Context, u)
3. 效果

img.png

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binder

type Binder struct{}

func NewBinder

func NewBinder() *Binder

func (*Binder) Binder

func (b *Binder) Binder(c echo.Context, i interface{}, args ...string) string

type CustomValidator

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

func NewCustomerValidator

func NewCustomerValidator() *CustomValidator

func (*CustomValidator) Validate

func (c *CustomValidator) Validate(i interface{}) error

type MsgV

type MsgV struct {
	Key   string
	Error string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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