2019-09-04 15:22:27 +03:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin/binding"
|
2020-04-29 10:08:00 +03:00
|
|
|
"github.com/go-playground/validator/v10"
|
2019-09-04 15:22:27 +03:00
|
|
|
)
|
|
|
|
|
2019-12-12 09:35:05 +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())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-12 09:35:05 +03:00
|
|
|
// validateCrmURL will validate CRM URL
|
|
|
|
func validateCrmURL(fl validator.FieldLevel) bool {
|
|
|
|
return regCommandName.Match([]byte(fl.Field().String()))
|
2019-09-04 15:22:27 +03:00
|
|
|
}
|