mg-transport-core/core/validator.go

21 lines
559 B
Go
Raw Normal View History

2019-09-04 15:22:27 +03:00
package core
import (
"github.com/gin-gonic/gin/binding"
2019-12-12 09:35:05 +03:00
"gopkg.in/go-playground/validator.v9"
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
}