mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 20:24:11 +08:00
OncePerServerBlock may now return an error
This commit is contained in:
parent
a518049fa2
commit
691204ceed
|
@ -68,7 +68,13 @@ func Load(filename string, input io.Reader) (Group, error) {
|
||||||
controller := &setup.Controller{
|
controller := &setup.Controller{
|
||||||
Config: &config,
|
Config: &config,
|
||||||
Dispenser: parse.NewDispenserTokens(filename, tokens),
|
Dispenser: parse.NewDispenserTokens(filename, tokens),
|
||||||
OncePerServerBlock: func(f func()) { onces[dir.name].Do(f) },
|
OncePerServerBlock: func(f func() error) error {
|
||||||
|
var err error
|
||||||
|
onces[dir.name].Do(func() {
|
||||||
|
err = f()
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
midware, err := dir.setup(controller)
|
midware, err := dir.setup(controller)
|
||||||
|
|
|
@ -19,8 +19,11 @@ type Controller struct {
|
||||||
|
|
||||||
// OncePerServerBlock is a function that executes f
|
// OncePerServerBlock is a function that executes f
|
||||||
// exactly once per server block, no matter how many
|
// exactly once per server block, no matter how many
|
||||||
// hosts are associated with it.
|
// hosts are associated with it. If it is the first
|
||||||
OncePerServerBlock func(f func())
|
// time, the function f is executed immediately
|
||||||
|
// (not deferred) and may return an error which is
|
||||||
|
// returned by OncePerServerBlock.
|
||||||
|
OncePerServerBlock func(f func() error) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTestController creates a new *Controller for
|
// NewTestController creates a new *Controller for
|
||||||
|
|
|
@ -55,9 +55,8 @@ func registerCallback(c *Controller, list *[]func() error) error {
|
||||||
funcs = append(funcs, fn)
|
funcs = append(funcs, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.OncePerServerBlock(func() {
|
return c.OncePerServerBlock(func() error {
|
||||||
*list = append(*list, funcs...)
|
*list = append(*list, funcs...)
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user