sv

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: MIT Imports: 11 Imported by: 5 modules, 4 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

simple_valid as sv

a simple paramater validator for iris , use middleware

use see test

// Define req valid struct
	type req struct {
		Name string `json:"name" url:"name" comment:"name" validate:"required"`
	}

// Use middleware
	app.Get("/", sv.Run(new(req)), func(ctx iris.Context) {
		req := ctx.Values().Get("sv").(*req) // <- this get req data 
		_, _ = ctx.JSON(iris.Map{"name": req.Name})
	})

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GlobalFailFunc = func(err error, ctx iris.Context) {
		ctx.StatusCode(iris.StatusBadRequest)
		_, _ = ctx.JSON(iris.Map{"detail": err.Error()})
		return
	}
	GlobalContextKey = "sv"
)
View Source
var (
	Warning *log.Logger
)

Functions

func InitValidator

func InitValidator()

InitValidator 初始化验证器

func Run

func Run(valid interface{}, mode ...string) iris.Handler

Types

type CanCheck

type CanCheck interface {
	Check() error
}

CanCheck 如果需要特殊校验,可以实现验证接口,或者通过自定义tag标签实现

type MyValidator

type MyValidator struct {
	Validate *validator.Validate
	Trans    ut.Translator
}

MyValidator 自定义验证器

var GlobalValidator MyValidator

GlobalValidator 全局验证器

func (*MyValidator) Check

func (m *MyValidator) Check(value interface{}) error

Check 验证器通用验证方法

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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