Add BlocklistSource interface and implementations for fetching blocklist data
- Introduced `BlocklistSource` interface with `Get` method to retrieve IPv4/IPv6 blocklists. - Added `blocklistSource` and `blocklistSourceZip` structures to support standard and ZIP-configured data sources.
This commit is contained in:
46
internal/daemon/blocklist/sources/source.go
Normal file
46
internal/daemon/blocklist/sources/source.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package sources
|
||||
|
||||
import (
|
||||
"git.kor-elf.net/kor-elf-shield/blocklist"
|
||||
"git.kor-elf.net/kor-elf-shield/blocklist/parser"
|
||||
)
|
||||
|
||||
type BlocklistSource interface {
|
||||
Get() (ipV4 parser.IPs, ipV6 parser.IPs, err error)
|
||||
}
|
||||
|
||||
type blocklistSource struct {
|
||||
url string
|
||||
parser parser.Parser
|
||||
config blocklist.Config
|
||||
}
|
||||
|
||||
func NewBlocklistSource(url string, parser parser.Parser, config blocklist.Config) BlocklistSource {
|
||||
return &blocklistSource{
|
||||
url: url,
|
||||
parser: parser,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *blocklistSource) Get() (ipV4 parser.IPs, ipV6 parser.IPs, err error) {
|
||||
return blocklist.GetSeparatedIPs(b.url, b.parser, b.config)
|
||||
}
|
||||
|
||||
type blocklistSourceZip struct {
|
||||
url string
|
||||
parser parser.Parser
|
||||
config blocklist.ConfigZip
|
||||
}
|
||||
|
||||
func NewBlocklistSourceZip(url string, parser parser.Parser, config blocklist.ConfigZip) BlocklistSource {
|
||||
return &blocklistSourceZip{
|
||||
url: url,
|
||||
parser: parser,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *blocklistSourceZip) Get() (ipV4 parser.IPs, ipV6 parser.IPs, err error) {
|
||||
return blocklist.GetZipSeparatedIPs(b.url, b.parser, b.config)
|
||||
}
|
||||
Reference in New Issue
Block a user