mg-transport-core/core/validator.go

21 lines
564 B
Go
Raw Normal View History

2019-09-04 15:22:27 +03:00
package core
import (
"github.com/gin-gonic/gin/binding"
"github.com/go-playground/validator/v10"
2019-09-04 15:22:27 +03:00
)
// init here will register `validatecrmurl` function for gin validator.
2019-09-04 15:22:27 +03:00
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.
2019-12-12 09:35:05 +03:00
func validateCrmURL(fl validator.FieldLevel) bool {
return regCommandName.Match([]byte(fl.Field().String()))
2019-09-04 15:22:27 +03:00
}