mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-01 00:23:48 +03:00
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
This commit is contained in:
parent
f978967e5e
commit
a17e9b6b02
3 changed files with 24 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue