Nexus/pkg/internal/web/blacklist.go
2025-03-29 00:26:05 +08:00

35 lines
560 B
Go

package web
import (
"bufio"
"os"
"github.com/rs/zerolog/log"
)
var ipBlocklist []string
func AddBlockIP(ip string) {
ipBlocklist = append(ipBlocklist, ip)
}
func ParseBlockIPList(path string) error {
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
ipBlocklist = append(ipBlocklist, scanner.Text())
}
if err := scanner.Err(); err != nil {
return err
}
log.Info().Int("count", len(ipBlocklist)).Msg("Block IP list parsed successfully.")
return nil
}