github.com/trigonella/mattermost-server@v5.11.1+incompatible/plugin/client.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package plugin
     5  
     6  import (
     7  	"github.com/hashicorp/go-plugin"
     8  )
     9  
    10  // Starts the serving of a Mattermost plugin over net/rpc. gRPC is not yet supported.
    11  //
    12  // Call this when your plugin is ready to start.
    13  func ClientMain(pluginImplementation interface{}) {
    14  	if impl, ok := pluginImplementation.(interface {
    15  		SetAPI(api API)
    16  	}); !ok {
    17  		panic("Plugin implementation given must embed plugin.MattermostPlugin")
    18  	} else {
    19  		impl.SetAPI(nil)
    20  	}
    21  
    22  	pluginMap := map[string]plugin.Plugin{
    23  		"hooks": &hooksPlugin{hooks: pluginImplementation},
    24  	}
    25  
    26  	plugin.Serve(&plugin.ServeConfig{
    27  		HandshakeConfig: handshake,
    28  		Plugins:         pluginMap,
    29  	})
    30  }
    31  
    32  type MattermostPlugin struct {
    33  	// API exposes the plugin api, and becomes available just prior to the OnActive hook.
    34  	API API
    35  }
    36  
    37  // SetAPI persists the given API interface to the plugin. It is invoked just prior to the
    38  // OnActivate hook, exposing the API for use by the plugin.
    39  func (p *MattermostPlugin) SetAPI(api API) {
    40  	p.API = api
    41  }