mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	* Add weighted-round-robin policy to loadbalance plugin Signed-off-by: Gabor Dozsa <gabor.dozsa@ibm.com>
		
			
				
	
	
		
			26 lines
		
	
	
		
			739 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			739 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Package loadbalance is a plugin for rewriting responses to do "load balancing"
 | |
| package loadbalance
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 
 | |
| 	"github.com/coredns/coredns/plugin"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| )
 | |
| 
 | |
| // RoundRobin is a plugin to rewrite responses for "load balancing".
 | |
| type LoadBalance struct {
 | |
| 	Next    plugin.Handler
 | |
| 	shuffle func(*dns.Msg) *dns.Msg
 | |
| }
 | |
| 
 | |
| // ServeDNS implements the plugin.Handler interface.
 | |
| func (lb LoadBalance) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
 | |
| 	rw := &LoadBalanceResponseWriter{ResponseWriter: w, shuffle: lb.shuffle}
 | |
| 	return plugin.NextOrFailure(lb.Name(), lb.Next, ctx, rw, r)
 | |
| }
 | |
| 
 | |
| // Name implements the Handler interface.
 | |
| func (lb LoadBalance) Name() string { return "loadbalance" }
 |