mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	Add roundrobin middleware
This middleware allows you to round robin a/aaaa records in a reply and maybe more in the future (i.e.) sort a packet?
This commit is contained in:
		
							
								
								
									
										19
									
								
								middleware/loadbalance/handler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								middleware/loadbalance/handler.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| // Package loadbalance is middleware for rewriting responses to do "load balancing" | ||||
| package loadbalance | ||||
|  | ||||
| import ( | ||||
| 	"github.com/miekg/coredns/middleware" | ||||
| 	"github.com/miekg/dns" | ||||
| 	"golang.org/x/net/context" | ||||
| ) | ||||
|  | ||||
| // RoundRobin is middleware to rewrite responses for "load balancing". | ||||
| type RoundRobin struct { | ||||
| 	Next middleware.Handler | ||||
| } | ||||
|  | ||||
| // ServeHTTP implements the middleware.Handler interface. | ||||
| func (rr RoundRobin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { | ||||
| 	wrr := NewRoundRobinResponseWriter(w) | ||||
| 	return rr.Next.ServeDNS(ctx, wrr, r) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user