mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
plugin/loadbalance: add parse and tests (#1947)
Automatically submitted.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package loadbalance
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
clog "github.com/coredns/coredns/plugin/pkg/log"
|
||||
@@ -18,8 +20,9 @@ func init() {
|
||||
}
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
for c.Next() {
|
||||
// TODO(miek): block and option parsing
|
||||
err := parse(c)
|
||||
if err != nil {
|
||||
return plugin.Error("loadbalance", err)
|
||||
}
|
||||
|
||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||
@@ -28,3 +31,20 @@ func setup(c *caddy.Controller) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parse(c *caddy.Controller) error {
|
||||
for c.Next() {
|
||||
args := c.RemainingArgs()
|
||||
switch len(args) {
|
||||
case 0:
|
||||
return nil
|
||||
case 1:
|
||||
if args[0] != "round_robin" {
|
||||
return fmt.Errorf("unknown policy: %s", args[0])
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return c.ArgErr()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user