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*.
|
||||
type Engine struct {
|
||||
handlers map[string]Handler
|
||||
catchall Handler
|
||||
hack Hack // data for temporary hackery (see hack.go)
|
||||
id string
|
||||
Stdout io.Writer
|
||||
|
@ -60,6 +61,10 @@ func (eng *Engine) Register(name string, handler Handler) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (eng *Engine) RegisterCatchall(catchall Handler) {
|
||||
eng.catchall = catchall
|
||||
}
|
||||
|
||||
// New initializes a new engine.
|
||||
func New() *Engine {
|
||||
eng := &Engine{
|
||||
|
@ -113,9 +118,13 @@ func (eng *Engine) Job(name string, args ...string) *Job {
|
|||
if eng.Logging {
|
||||
job.Stderr.Add(utils.NopWriteCloser(eng.Stderr))
|
||||
}
|
||||
handler, exists := eng.handlers[name]
|
||||
if exists {
|
||||
job.handler = handler
|
||||
if eng.catchall != nil {
|
||||
job.handler = eng.catchall
|
||||
} else {
|
||||
handler, exists := eng.handlers[name]
|
||||
if exists {
|
||||
job.handler = handler
|
||||
}
|
||||
}
|
||||
return job
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue