-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
59 lines (42 loc) · 1.05 KB
/
setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package columbus
import (
"runtime"
"strconv"
"sync/atomic"
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
)
func init() { plugin.Register("columbus", setup) }
func setup(c *caddy.Controller) error {
c.Next()
var err error
if DomainsChan == nil {
buffSize := 10000
if c.NextArg() {
buffSize, err = strconv.Atoi(c.Val())
if err != nil {
log.Fatalf("Failed to convert columbus.buff %s to int: %s\n", c.Val(), err)
}
}
DomainsChan = make(chan *string, buffSize)
}
if InsertWorkers == nil || !InsertWorkers.Load() {
InsertWorkers = new(atomic.Bool)
nWorkers := runtime.NumCPU()
if c.NextArg() {
nWorkers, err = strconv.Atoi(c.Val())
if err != nil {
log.Fatalf("Failed to convert columbus.workers %s to int: %s\n", c.Val(), err)
}
}
for i := 0; i < nWorkers; i++ {
go insertWorker()
}
InsertWorkers.Store(true)
}
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
return Columbus{Next: next}
})
return nil
}