cic-custodial/internal/api/validator.go
Mohammed Sohail add7f2a442
refactor: ctx propagation, api handlers
* 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
2023-02-24 16:46:46 +00:00

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()
}