aboutsummaryrefslogtreecommitdiff
path: root/plugin/loadbalance/handler.go
blob: 8b84e1c5c0018ac2d48dd02b884dca4199e6df49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 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" }