Move setting plugin helpers to a seperate function to avoid breaking changes. (#10809)

Этот коммит содержится в:
Christopher Speller
2019-05-08 11:54:52 -07:00
коммит произвёл Harrison Healey
родитель 6ce3cc6921
Коммит 66cb36f5dc
3 изменённых файлов: 15 добавлений и 6 удалений

Просмотреть файл

@@ -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
}

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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)