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 ¶
Types ¶
type MyValidator ¶
type MyValidator struct { Validate *validator.Validate Trans ut.Translator }
MyValidator 自定义验证器
var GlobalValidator MyValidator
GlobalValidator 全局验证器
Click to show internal directories.
Click to hide internal directories.