added superuser ips whitelist

This commit is contained in:
Gani Georgiev committed 2026-05-05 13:04:06 +03:00
1 parent fe2d90641c
commit 21a5524fed
34 files changed
+1224 -47

No files matched your search

+28
View File
@@ -1,6 +1,7 @@
package validators
import (
"net/netip"
"regexp"
validation "github.com/go-ozzo/ozzo-validation/v4"
@@ -27,3 +28,30 @@ func IsRegex(value any) error {
return nil
}
// IPOrSubnet checks whether the validated value is an individual
// IPv4/IPv6 or CIDR subnet.
func IPOrSubnet(value any) error {
v, ok := value.(string)
if !ok {
return ErrUnsupportedValueType
}
if v == "" {
return nil // nothing to check
}
// subnet
_, err := netip.ParsePrefix(v)
if err == nil {
return nil
}
// individual IP
_, err = netip.ParseAddr(v)
if err == nil {
return nil
}
return validation.NewError("validation_invlaid_ip_or_subnet", "invalid IP or CIDR subnet")
}