add trusted proxies

This commit is contained in:
Aine
2022-11-27 00:30:50 +02:00
parent 8d6c4aeafe
commit fcd6110790
11 changed files with 95 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"net"
"strconv"
"strings"
@@ -22,6 +23,16 @@ func SetDomains(slice []string) {
domains = slice
}
// AddrIP returns IP from a network address
func AddrIP(addr net.Addr) string {
key := addr.String()
host, _, _ := net.SplitHostPort(key) //nolint:errcheck // either way it's ok
if host != "" {
key = host
}
return key
}
// SanitizeDomain checks that input domain is available for use
func SanitizeDomain(domain string) string {
domain = strings.TrimSpace(domain)