mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	* Update Caddy to 1.0.1, and update import path This fix updates caddy to 1.0.1 and also updates the import path to github.com/caddyserver/caddy This fix fixes 2959 Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Also update plugin.cfg Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Update and bump zplugin.go Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
		
			
				
	
	
		
			51 lines
		
	
	
		
			887 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			887 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package loadbalance
 | 
						|
 | 
						|
import (
 | 
						|
	"fmt"
 | 
						|
 | 
						|
	"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("loadbalance")
 | 
						|
 | 
						|
func init() {
 | 
						|
	caddy.RegisterPlugin("loadbalance", caddy.Plugin{
 | 
						|
		ServerType: "dns",
 | 
						|
		Action:     setup,
 | 
						|
	})
 | 
						|
}
 | 
						|
 | 
						|
func setup(c *caddy.Controller) error {
 | 
						|
	err := parse(c)
 | 
						|
	if err != nil {
 | 
						|
		return plugin.Error("loadbalance", err)
 | 
						|
	}
 | 
						|
 | 
						|
	dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
 | 
						|
		return RoundRobin{Next: next}
 | 
						|
	})
 | 
						|
 | 
						|
	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()
 | 
						|
}
 |