add GetValidate func to get the default validator (#558)

* add GetValidate func to get the default validator

* warden server expose GetValidate func

Co-authored-by: John Sun <sunqiang@styd.cn>
pull/574/head
Klaus 5 years ago committed by GitHub
parent d57df0b443
commit 52cb7ec27f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      pkg/net/http/blademaster/binding/binding.go
  2. 5
      pkg/net/http/blademaster/binding/default_validator.go
  3. 5
      pkg/net/rpc/warden/validate.go

@ -37,6 +37,9 @@ type StructValidator interface {
// NOTE: if the key already exists, the previous validation function will be replaced. // NOTE: if the key already exists, the previous validation function will be replaced.
// NOTE: this method is not thread-safe it is intended that these all be registered prior to any validation // NOTE: this method is not thread-safe it is intended that these all be registered prior to any validation
RegisterValidation(string, validator.Func) error RegisterValidation(string, validator.Func) error
//GetValidate return the default validate
GetValidate() *validator.Validate
} }
// Validator default validator. // Validator default validator.

@ -43,3 +43,8 @@ func kindOfData(data interface{}) reflect.Kind {
} }
return valueType return valueType
} }
func (v *defaultValidator) GetValidate() *validator.Validate {
v.lazyinit()
return v.validate
}

@ -29,3 +29,8 @@ func (s *Server) validate() grpc.UnaryServerInterceptor {
func (s *Server) RegisterValidation(key string, fn validator.Func) error { func (s *Server) RegisterValidation(key string, fn validator.Func) error {
return validate.RegisterValidation(key, fn) return validate.RegisterValidation(key, fn)
} }
//GetValidate return the default validate
func (s *Server) GetValidate() *validator.Validate {
return validate
}

Loading…
Cancel
Save