package validate import ( "context" "git.diulo.com/mogfee/kit/errors" "git.diulo.com/mogfee/kit/middleware" "strings" ) func Server() middleware.Middleware { return func(handler middleware.Handler) middleware.Handler { return func(ctx context.Context, a any) (any, error) { if v, ok := a.(interface { Validate() error }); ok { if err := v.Validate(); err != nil { if a, ok := err.(interface { Field() string Reason() string }); ok { field := a.Field() return nil, errors.BadRequest("InvalidArgument", "").WithMetadata(map[string]string{ strings.ToLower(field[0:1]) + field[1:]: a.Reason(), }) } } } return handler(ctx, a) } } }