From 66cb36f5dc35e75f51e08734374b8009d96a8392 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 8 May 2019 11:54:52 -0700 Subject: [PATCH] Move setting plugin helpers to a seperate function to avoid breaking changes. (#10809) --- plugin/client.go | 12 +++++++++--- plugin/client_rpc.go | 6 ++++-- plugin/plugintest/example_hello_user_test.go | 3 ++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/plugin/client.go b/plugin/client.go index bc51540503..e445f9e1e0 100644 --- a/plugin/client.go +++ b/plugin/client.go @@ -17,11 +17,13 @@ const ( // Call this when your plugin is ready to start. func ClientMain(pluginImplementation interface{}) { if impl, ok := pluginImplementation.(interface { - SetAPI(api API, helpers Helpers) + SetAPI(api API) + SetHelpers(helpers Helpers) }); !ok { panic("Plugin implementation given must embed plugin.MattermostPlugin") } else { - impl.SetAPI(nil, nil) + impl.SetAPI(nil) + impl.SetHelpers(nil) } pluginMap := map[string]plugin.Plugin{ @@ -42,7 +44,11 @@ type MattermostPlugin struct { // SetAPI persists the given API interface to the plugin. It is invoked just prior to the // OnActivate hook, exposing the API for use by the plugin. -func (p *MattermostPlugin) SetAPI(api API, helpers Helpers) { +func (p *MattermostPlugin) SetAPI(api API) { p.API = api +} + +// SetHelpers does the same thing as SetAPI except for the plugin helpers. +func (p *MattermostPlugin) SetHelpers(helpers Helpers) { p.Helpers = helpers } diff --git a/plugin/client_rpc.go b/plugin/client_rpc.go index 228d673ef6..a43107c93c 100644 --- a/plugin/client_rpc.go +++ b/plugin/client_rpc.go @@ -196,9 +196,11 @@ func (s *hooksRPCServer) OnActivate(args *Z_OnActivateArgs, returns *Z_OnActivat } if mmplugin, ok := s.impl.(interface { - SetAPI(api API, helpers Helpers) + SetAPI(api API) + SetHelpers(helpers Helpers) }); ok { - mmplugin.SetAPI(s.apiRPCClient, &HelpersImpl{API: s.apiRPCClient}) + mmplugin.SetAPI(s.apiRPCClient) + mmplugin.SetHelpers(&HelpersImpl{API: s.apiRPCClient}) } if mmplugin, ok := s.impl.(interface { diff --git a/plugin/plugintest/example_hello_user_test.go b/plugin/plugintest/example_hello_user_test.go index b46991d971..145f3fadac 100644 --- a/plugin/plugintest/example_hello_user_test.go +++ b/plugin/plugintest/example_hello_user_test.go @@ -46,7 +46,8 @@ func Example() { defer helpers.AssertExpectations(t) p := &HelloUserPlugin{} - p.SetAPI(api, helpers) + p.SetAPI(api) + p.SetHelpers(helpers) w := httptest.NewRecorder() r := httptest.NewRequest("GET", "/", nil)