1 Star 0 Fork 0

SasukeBo/go-micro

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
validator.go 548 Bytes
Copy Edit Raw Blame History
汪波 authored 2023-02-23 10:27 . fix: 替换包名
package validator
import (
"context"
"gitee.com/sasukebo/go-micro/v4/errors"
"gitee.com/sasukebo/go-micro/v4/server"
)
type Validator interface {
Validate() error
}
func NewHandlerWrapper() server.HandlerWrapper {
return func(fn server.HandlerFunc) server.HandlerFunc {
return func(ctx context.Context, req server.Request, rsp interface{}) error {
if v, ok := req.Body().(Validator); ok {
if err := v.Validate(); err != nil {
return errors.BadRequest(req.Service(), "%v", err)
}
}
return fn(ctx, req, rsp)
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sasukebo/go-micro.git
git@gitee.com:sasukebo/go-micro.git
sasukebo
go-micro
go-micro
6e18eb58b836

Search