diff --git a/plugins/client.go b/plugins/client.go index f89253d..ab429f0 100644 --- a/plugins/client.go +++ b/plugins/client.go @@ -15,7 +15,7 @@ import ( const ( versionMimetype = "appplication/vnd.docker.plugins.v1+json" - defaultTimeOut = 120 + defaultTimeOut = 30 ) func NewClient(addr string) *Client { diff --git a/plugins/plugins.go b/plugins/plugins.go index af2111e..4751948 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -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 +}