Compare commits

2 Commits

2 changed files with 41 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ type Config struct {
}
// NewConfig creates a new Config with default values.
// limit is the maximum number of items to process or validate. 0 means no limit.
func NewConfig(limit uint) Config {
return Config{
Limit: limit,

40
examples/spamhaus.go Normal file
View File

@@ -0,0 +1,40 @@
package main
import (
"encoding/json"
"fmt"
"git.kor-elf.net/kor-elf-shield/blocklist"
"git.kor-elf.net/kor-elf-shield/blocklist/parser"
)
/**
* An example of how to get a list of bad IP addresses from the service https://www.spamhaus.org/blocklists/do-not-route-or-peer/
*/
type lineJson struct {
IP string `json:"cidr"`
}
func main() {
url := "https://www.spamhaus.org/drop/drop_v4.json"
//url := "https://www.spamhaus.org/drop/drop_v6.json"
pars, err := parser.NewJsonLines(func(item json.RawMessage) (string, error) {
var line lineJson
if err := json.Unmarshal(item, &line); err != nil {
return "", fmt.Errorf("unmarshal json item: %w", err)
}
return line.IP, nil
})
if err != nil {
panic(err)
}
// limit 0 - no limit
limit := uint(0)
config := blocklist.NewConfig(limit)
ips, err := blocklist.Get(url, pars, config)
if err != nil {
panic(err)
}
fmt.Println(ips)
}