mirror of
https://github.com/coredns/coredns.git
synced 2025-11-03 10:43:20 -05:00
Add traffic plugin
This allows for advanced loadbalancing and maybe geoIP loadbalancing. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
40
plugin/traffic/setup.go
Normal file
40
plugin/traffic/setup.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package traffic
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
clog "github.com/coredns/coredns/plugin/pkg/log"
|
||||
|
||||
"github.com/caddyserver/caddy"
|
||||
)
|
||||
|
||||
var log = clog.NewWithPlugin("traffic")
|
||||
|
||||
func init() { plugin.Register("traffic", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
rand.Seed(int64(time.Now().Nanosecond()))
|
||||
if err := parse(c); err != nil {
|
||||
return plugin.Error("traffic", err)
|
||||
}
|
||||
|
||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||
return &Traffic{Next: next, assignments: make(map[string]assignment)}
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parse(c *caddy.Controller) error {
|
||||
for c.Next() {
|
||||
args := c.RemainingArgs()
|
||||
if len(args) != 0 {
|
||||
return c.ArgErr()
|
||||
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user