golib/net/ipgate/format.go
AJ ONeal e007da3e44
feat(net/ipgate): IP allowlist/blocklist via PrefixSet and DomainSet
PrefixSet: git-backed CIDR files via gitshallow, refreshed every 47 min.
DomainSet: CSV of static IPs/prefixes + hostnames resolved every 5 min;
retains stale IPs on resolve failure. Both use atomic-swapped ipcohort.Cohort
for lock-free reads.

replace directives in go.mod point to local siblings; remove after tagging.
2026-05-22 11:16:33 -04:00

32 lines
468 B
Go

package ipgate
import (
"log/slog"
"strconv"
"strings"
)
func log() *slog.Logger { return slog.Default().WithGroup("ipgate") }
func commaify(n int) string {
s := strconv.Itoa(n)
if n < 0 {
return "-" + commaify(-n)
}
if len(s) <= 3 {
return s
}
rem := len(s) % 3
if rem == 0 {
rem = 3
}
var result strings.Builder
result.WriteString(s[:rem])
for i := rem; i < len(s); i += 3 {
result.WriteString("," + s[i:i+3])
}
return result.String()
}