diff --git a/plugins/plugins.go b/plugins/plugins.go index 90ffa445d459a..ec7b67523073d 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -9,7 +9,7 @@ import ( var ( activePlugins = &plugins{plugins: make(map[string]*Plugin)} - extpointHandlers = make(map[string]func(string, *Client)) + extpointHandlers = &handlers{handlers: make(map[string]func(string, *Client))} ) type plugins struct { @@ -17,6 +17,11 @@ type plugins struct { plugins map[string]*Plugin } +type handlers struct { + sync.Mutex + handlers map[string]func(string, *Client) +} + type Manifest struct { Implements []string } @@ -44,8 +49,11 @@ func (p *Plugin) Activate() error { } p.Manifest = m + extpointHandlers.Lock() + defer extpointHandlers.Unlock() + for _, iface := range m.Implements { - handler, handled := extpointHandlers[iface] + handler, handled := extpointHandlers.handlers[iface] if !handled { continue } @@ -103,5 +111,7 @@ func Active() []*Plugin { } func Handle(iface string, fn func(string, *Client)) { - extpointHandlers[iface] = fn + extpointHandlers.Lock() + defer extpointHandlers.Unlock() + extpointHandlers.handlers[iface] = fn }