From 1501e01cae2f713e468a2b3275c185bc4f498599 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Fri, 15 May 2015 04:07:59 -0700 Subject: [PATCH] Allow to call back when a plugin is loaded. Signed-off-by: Madhu Venugopal --- plugins/client.go | 2 +- plugins/plugins.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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 +}