Skip to content

Commit 879507d

Browse files
committed
Chore: refactor rbl code into a pkg
1 parent 50590f5 commit 879507d

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

collector/collector.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"sync"
55

66
"github.com/Luzilla/dnsbl_exporter/pkg/dns"
7+
"github.com/Luzilla/dnsbl_exporter/pkg/rbl"
78
x "github.com/miekg/dns"
89
"github.com/prometheus/client_golang/prometheus"
910
log "github.com/sirupsen/logrus"
@@ -85,10 +86,10 @@ func (c *RblCollector) Collect(ch chan<- prometheus.Metric) {
8586

8687
log.Debugln("Checking ...", host)
8788

88-
rbl := NewRbl(dns.New(new(x.Client), c.resolver))
89-
rbl.Update(host, c.rbls)
89+
r := rbl.New(dns.New(new(x.Client), c.resolver))
90+
r.Update(host, c.rbls)
9091

91-
for _, result := range rbl.Results {
92+
for _, result := range r.Results {
9293
// this is an "error" from the RBL
9394
if result.Error {
9495
log.Errorln(result.Text)

collector/rbl.go renamed to pkg/rbl/rbl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package collector
1+
package rbl
22

33
import (
44
"fmt"
@@ -28,7 +28,7 @@ type Rbl struct {
2828
}
2929

3030
// NewRbl ... factory
31-
func NewRbl(util *dns.DNSUtil) Rbl {
31+
func New(util *dns.DNSUtil) Rbl {
3232
var results []Rblresult
3333

3434
rbl := Rbl{
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package collector
1+
package rbl_test
22

33
import (
44
"os"
55
"testing"
66

77
"github.com/Luzilla/dnsbl_exporter/pkg/dns"
8+
"github.com/Luzilla/dnsbl_exporter/pkg/rbl"
89
x "github.com/miekg/dns"
910
log "github.com/sirupsen/logrus"
1011
)
@@ -15,10 +16,10 @@ func TestUpdate(t *testing.T) {
1516

1617
d := dns.New(new(x.Client), "0.0.0.0:53")
1718

18-
rbl := NewRbl(d)
19-
rbl.Update("this.is.not.an.ip", []string{"cbl.abuseat.org"})
19+
r := rbl.New(d)
20+
r.Update("this.is.not.an.ip", []string{"cbl.abuseat.org"})
2021

21-
if len(rbl.Results) > 0 {
22-
t.Errorf("Got a result, but shouldn't have: %v", rbl.Results)
22+
if len(r.Results) > 0 {
23+
t.Errorf("Got a result, but shouldn't have: %v", r.Results)
2324
}
2425
}

0 commit comments

Comments
 (0)