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:
		
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
									
									
									
									
								
							@@ -4,7 +4,6 @@ go 1.16
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	git.prolicht.digital/pub/healthcheck v1.0.1
 | 
						git.prolicht.digital/pub/healthcheck v1.0.1
 | 
				
			||||||
	github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
 | 
					 | 
				
			||||||
	github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 // indirect
 | 
						github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 // indirect
 | 
				
			||||||
	github.com/evanphx/json-patch v0.5.2
 | 
						github.com/evanphx/json-patch v0.5.2
 | 
				
			||||||
	github.com/gin-contrib/sessions v0.0.5
 | 
						github.com/gin-contrib/sessions v0.0.5
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							@@ -9,8 +9,6 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
 | 
				
			|||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
 | 
					github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
 | 
				
			||||||
github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
 | 
					github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
 | 
				
			||||||
github.com/antonlindstrom/pgstore v0.0.0-20200229204646-b08ebf1105e0/go.mod h1:2Ti6VUHVxpC0VSmTZzEvpzysnaGAfGBOoMIz5ykPyyw=
 | 
					github.com/antonlindstrom/pgstore v0.0.0-20200229204646-b08ebf1105e0/go.mod h1:2Ti6VUHVxpC0VSmTZzEvpzysnaGAfGBOoMIz5ykPyyw=
 | 
				
			||||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
 | 
					 | 
				
			||||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
 | 
					 | 
				
			||||||
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
 | 
					github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
 | 
				
			||||||
github.com/bos-hieu/mongostore v0.0.2/go.mod h1:8AbbVmDEb0yqJsBrWxZIAZOxIfv/tsP8CDtdHduZHGg=
 | 
					github.com/bos-hieu/mongostore v0.0.2/go.mod h1:8AbbVmDEb0yqJsBrWxZIAZOxIfv/tsP8CDtdHduZHGg=
 | 
				
			||||||
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
 | 
					github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,6 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/asaskevich/govalidator"
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
	"github.com/gin-gonic/gin/binding"
 | 
						"github.com/gin-gonic/gin/binding"
 | 
				
			||||||
	"github.com/go-playground/validator/v10"
 | 
						"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 {
 | 
					var dnsList validator.Func = func(fl validator.FieldLevel) bool {
 | 
				
			||||||
	dnsListStr := fl.Field().String()
 | 
						dnsListStr := fl.Field().String()
 | 
				
			||||||
	dnsList := common.ParseStringList(dnsListStr)
 | 
						dnsList := common.ParseStringList(dnsListStr)
 | 
				
			||||||
 | 
						validate := binding.Validator.Engine().(*validator.Validate)
 | 
				
			||||||
	for i := range dnsList {
 | 
						for i := range dnsList {
 | 
				
			||||||
		ip := net.ParseIP(dnsList[i])
 | 
							ip := net.ParseIP(dnsList[i])
 | 
				
			||||||
		if ip == nil && !govalidator.IsDNSName(dnsList[i]) {
 | 
							if ip == nil {
 | 
				
			||||||
			return false
 | 
								err := validate.Var(dnsList[i], "fqdn")
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return false
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return true
 | 
						return true
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user