mirror of
				https://github.com/h44z/wg-portal.git
				synced 2025-11-03 23:56:18 +00:00 
			
		
		
		
	use go-playground/validator instead of asaskevich/govalidator (#46)
This commit is contained in:
		@@ -12,7 +12,6 @@ import (
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/asaskevich/govalidator"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"github.com/gin-gonic/gin/binding"
 | 
			
		||||
	"github.com/go-playground/validator/v10"
 | 
			
		||||
@@ -41,10 +40,14 @@ var cidrList validator.Func = func(fl validator.FieldLevel) bool {
 | 
			
		||||
var dnsList validator.Func = func(fl validator.FieldLevel) bool {
 | 
			
		||||
	dnsListStr := fl.Field().String()
 | 
			
		||||
	dnsList := common.ParseStringList(dnsListStr)
 | 
			
		||||
	validate := binding.Validator.Engine().(*validator.Validate)
 | 
			
		||||
	for i := range dnsList {
 | 
			
		||||
		ip := net.ParseIP(dnsList[i])
 | 
			
		||||
		if ip == nil && !govalidator.IsDNSName(dnsList[i]) {
 | 
			
		||||
			return false
 | 
			
		||||
		if ip == nil {
 | 
			
		||||
			err := validate.Var(dnsList[i], "fqdn")
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return false
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return true
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user