mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 08:44:17 -04:00
Minor refactor of proxy parsing to make upstreams re-usable in other plugins (#1426)
This commit is contained in:
@@ -28,6 +28,18 @@ type staticUpstream struct {
|
||||
func NewStaticUpstreams(c *caddyfile.Dispenser) ([]Upstream, error) {
|
||||
var upstreams []Upstream
|
||||
for c.Next() {
|
||||
u, err := NewStaticUpstream(c)
|
||||
if err != nil {
|
||||
return upstreams, err
|
||||
}
|
||||
upstreams = append(upstreams, u)
|
||||
}
|
||||
return upstreams, nil
|
||||
}
|
||||
|
||||
// NewStaticUpstream parses the configuration of a single upstream
|
||||
// starting from the FROM
|
||||
func NewStaticUpstream(c *caddyfile.Dispenser) (Upstream, error) {
|
||||
upstream := &staticUpstream{
|
||||
from: ".",
|
||||
HealthCheck: healthcheck.HealthCheck{
|
||||
@@ -38,28 +50,28 @@ func NewStaticUpstreams(c *caddyfile.Dispenser) ([]Upstream, error) {
|
||||
}
|
||||
|
||||
if !c.Args(&upstream.from) {
|
||||
return upstreams, c.ArgErr()
|
||||
return upstream, c.ArgErr()
|
||||
}
|
||||
upstream.from = plugin.Host(upstream.from).Normalize()
|
||||
|
||||
to := c.RemainingArgs()
|
||||
if len(to) == 0 {
|
||||
return upstreams, c.ArgErr()
|
||||
return upstream, c.ArgErr()
|
||||
}
|
||||
|
||||
// process the host list, substituting in any nameservers in files
|
||||
toHosts, err := dnsutil.ParseHostPortOrFile(to...)
|
||||
if err != nil {
|
||||
return upstreams, err
|
||||
return upstream, err
|
||||
}
|
||||
|
||||
if len(toHosts) > max {
|
||||
return upstreams, fmt.Errorf("more than %d TOs configured: %d", max, len(toHosts))
|
||||
return upstream, fmt.Errorf("more than %d TOs configured: %d", max, len(toHosts))
|
||||
}
|
||||
|
||||
for c.NextBlock() {
|
||||
if err := parseBlock(c, upstream); err != nil {
|
||||
return upstreams, err
|
||||
return upstream, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,9 +87,7 @@ func NewStaticUpstreams(c *caddyfile.Dispenser) ([]Upstream, error) {
|
||||
}
|
||||
upstream.Start()
|
||||
|
||||
upstreams = append(upstreams, upstream)
|
||||
}
|
||||
return upstreams, nil
|
||||
return upstream, nil
|
||||
}
|
||||
|
||||
func parseBlock(c *caddyfile.Dispenser, u *staticUpstream) error {
|
||||
|
||||
Reference in New Issue
Block a user