mg-transport-core/core/validator.go
2019-12-12 12:06:38 +03:00

21 lines
559 B
Go

package core
import (
"github.com/gin-gonic/gin/binding"
"gopkg.in/go-playground/validator.v9"
)
// init here will register `validatecrmurl` function for gin validator
func init() {
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
if err := v.RegisterValidation("validatecrmurl", validateCrmURL); err != nil {
panic("cannot register crm url validator: " + err.Error())
}
}
}
// validateCrmURL will validate CRM URL
func validateCrmURL(fl validator.FieldLevel) bool {
return regCommandName.Match([]byte(fl.Field().String()))
}