Allow to call back when a plugin is loaded.

Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2015-05-15 04:07:59 -07:00 committed by David Calavera
parent 774251695e
commit 1501e01cae
2 changed files with 16 additions and 2 deletions

View file

@ -15,7 +15,7 @@ import (
const (
versionMimetype = "appplication/vnd.docker.plugins.v1+json"
defaultTimeOut = 120
defaultTimeOut = 30
)
func NewClient(addr string) *Client {

View file

@ -16,7 +16,10 @@ type plugins struct {
plugins map[string]*Plugin
}
var storage = plugins{plugins: make(map[string]*Plugin)}
var (
storage = plugins{plugins: make(map[string]*Plugin)}
extpointHandlers = make(map[string]func(string, *Client))
)
type Manifest struct {
Implements []string
@ -39,6 +42,13 @@ func (p *Plugin) activate() error {
logrus.Debugf("%s's manifest: %v", p.Name, m)
p.Manifest = m
for _, iface := range m.Implements {
handler, handled := extpointHandlers[iface]
if !handled {
continue
}
handler(p.Name, p.Client)
}
return nil
}
@ -84,3 +94,7 @@ func Get(name, imp string) (*Plugin, error) {
}
return nil, ErrNotImplements
}
func Handle(iface string, fn func(string, *Client)) {
extpointHandlers[iface] = fn
}