1
0
mirror of synced 2024-11-23 20:46:01 +03:00
mg-transport-telegram/src/validator.go

25 lines
643 B
Go
Raw Normal View History

package main
import (
"reflect"
"regexp"
"github.com/gin-gonic/gin/binding"
2018-08-20 13:57:14 +03:00
"gopkg.in/go-playground/validator.v8"
)
2018-08-15 17:56:36 +03:00
func setValidation() {
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
v.RegisterValidation("validatecrmurl", validateCrmURL)
}
}
2018-08-20 13:57:14 +03:00
func validateCrmURL(
v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value,
field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string,
) bool {
regCommandName := regexp.MustCompile(`https://?[\da-z.-]+\.(retailcrm\.(ru|pro)|ecomlogic\.com)`)
2018-08-20 13:57:14 +03:00
return regCommandName.Match([]byte(field.Interface().(string)))
}