mirror of
https://github.com/therootcompany/golib.git
synced 2026-11-04 06:55:00 +00:00
Rename net/ipgate to net/ippolicy and compose independently refreshed whitelist and blacklist sources into one IP decision policy. - rename slog group and error prefixes from ipgate to ippolicy - delete unused ParseDomainSet and RecordReader from domainsetcsv.go - rewrite README to match the actual Config API - document nil-whitelist behavior on New() - bump iplist dependency to v0.8.5 - go mod tidy: remove stale ipgate and iplist entries
32 lines
460 B
Go
32 lines
460 B
Go
package ippolicy
|
|
|
|
import (
|
|
"log/slog"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func log() *slog.Logger { return slog.Default().WithGroup("ippolicy") }
|
|
|
|
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 out strings.Builder
|
|
out.WriteString(s[:rem])
|
|
for i := rem; i < len(s); i += 3 {
|
|
out.WriteString("," + s[i:i+3])
|
|
}
|
|
return out.String()
|
|
}
|