mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
engine: allow registering a "catchall" handler which receives all commands
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
9422451ac3
commit
68d3e75750
1 changed files with 12 additions and 3 deletions
|
@ -43,6 +43,7 @@ func unregister(name string) {
|
||||||
// containers by executing *jobs*.
|
// containers by executing *jobs*.
|
||||||
type Engine struct {
|
type Engine struct {
|
||||||
handlers map[string]Handler
|
handlers map[string]Handler
|
||||||
|
catchall Handler
|
||||||
hack Hack // data for temporary hackery (see hack.go)
|
hack Hack // data for temporary hackery (see hack.go)
|
||||||
id string
|
id string
|
||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
|
@ -60,6 +61,10 @@ func (eng *Engine) Register(name string, handler Handler) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (eng *Engine) RegisterCatchall(catchall Handler) {
|
||||||
|
eng.catchall = catchall
|
||||||
|
}
|
||||||
|
|
||||||
// New initializes a new engine.
|
// New initializes a new engine.
|
||||||
func New() *Engine {
|
func New() *Engine {
|
||||||
eng := &Engine{
|
eng := &Engine{
|
||||||
|
@ -113,9 +118,13 @@ func (eng *Engine) Job(name string, args ...string) *Job {
|
||||||
if eng.Logging {
|
if eng.Logging {
|
||||||
job.Stderr.Add(utils.NopWriteCloser(eng.Stderr))
|
job.Stderr.Add(utils.NopWriteCloser(eng.Stderr))
|
||||||
}
|
}
|
||||||
handler, exists := eng.handlers[name]
|
if eng.catchall != nil {
|
||||||
if exists {
|
job.handler = eng.catchall
|
||||||
job.handler = handler
|
} else {
|
||||||
|
handler, exists := eng.handlers[name]
|
||||||
|
if exists {
|
||||||
|
job.handler = handler
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return job
|
return job
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue