Commit 22367801 authored by Matthew Holt's avatar Matthew Holt

Add ServerBlockIndex and ServerBlockHosts to Controller

This way, Setup functions have access to the list of hosts that share the server block, and also, if needed for some reason, the index of the server block in the input
parent 691204ce
......@@ -44,7 +44,7 @@ func Load(filename string, input io.Reader) (Group, error) {
// Each server block represents similar hosts/addresses.
// Iterate each server block and make a config for each one,
// executing the directives that were parsed.
for _, sb := range serverBlocks {
for i, sb := range serverBlocks {
onces := makeOnces()
for _, addr := range sb.Addresses {
......@@ -75,6 +75,8 @@ func Load(filename string, input io.Reader) (Group, error) {
})
return err
},
ServerBlockIndex: i,
ServerBlockHosts: sb.HostList(),
}
midware, err := dir.setup(controller)
......
......@@ -312,3 +312,15 @@ type (
Host, Port string
}
)
// HostList converts the list of addresses (hosts)
// that are associated with this server block into
// a slice of strings. Each string is a host:port
// combination.
func (sb serverBlock) HostList() []string {
sbHosts := make([]string, len(sb.Addresses))
for j, addr := range sb.Addresses {
sbHosts[j] = net.JoinHostPort(addr.Host, addr.Port)
}
return sbHosts
}
......@@ -24,6 +24,15 @@ type Controller struct {
// (not deferred) and may return an error which is
// returned by OncePerServerBlock.
OncePerServerBlock func(f func() error) error
// ServerBlockIndex is the 0-based index of the
// server block as it appeared in the input.
ServerBlockIndex int
// ServerBlockHosts is a list of hosts that are
// associated with this server block. All these
// hosts, consequently, share the same tokens.
ServerBlockHosts []string
}
// NewTestController creates a new *Controller for
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment