mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-05 15:16:46 +01:00
Mohammed Sohail
add7f2a442
* use context timeout middleware for correct ctx propagation * Fix bind error handling * Fix validation error handling * Fix HTTP error handling (4XX) * tasker client now accepts ctx * add recovery and body size middleware
29 lines
629 B
Go
29 lines
629 B
Go
package api
|
|
|
|
import (
|
|
"github.com/celo-org/celo-blockchain/common"
|
|
"github.com/go-playground/validator/v10"
|
|
)
|
|
|
|
type Validator struct {
|
|
ValidatorProvider *validator.Validate
|
|
}
|
|
|
|
func (v *Validator) Validate(i interface{}) error {
|
|
if err := v.ValidatorProvider.Struct(i); err != nil {
|
|
if _, ok := err.(validator.ValidationErrors); ok {
|
|
return NewBadRequestError(err.(validator.ValidationErrors).Error())
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func EthChecksumValidator(fl validator.FieldLevel) bool {
|
|
addr, err := common.NewMixedcaseAddressFromString(fl.Field().String())
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
return addr.ValidChecksum()
|
|
}
|