mirror of
https://github.com/mattermost/mattermost.git
synced 2026-08-27 05:37:15 -05:00
more plugin doc updates (#7767)
This commit is contained in:
committed by
Christopher Speller
parent
71dd21ef3d
commit
d2cff9b77c
+4
-2
@@ -7,8 +7,10 @@ import (
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
// API implementations can be used to retrieve data or perform actions on behalf of the plugin. Most
|
||||
// methods have direct counterparts in the REST API and very similar behavior.
|
||||
// The API can be used to retrieve data or perform actions on behalf of the plugin. Most methods
|
||||
// have direct counterparts in the REST API and very similar behavior.
|
||||
//
|
||||
// Plugins can obtain access to the API by implementing the OnActivate hook.
|
||||
type API interface {
|
||||
// LoadPluginConfiguration loads the plugin's configuration. dest should be a pointer to a
|
||||
// struct that the configuration JSON can be unmarshalled to.
|
||||
|
||||
@@ -8,16 +8,16 @@ import (
|
||||
"github.com/mattermost/mattermost-server/plugin/rpcplugin"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
type HelloUserPlugin struct {
|
||||
api plugin.API
|
||||
}
|
||||
|
||||
func (p *MyPlugin) OnActivate(api plugin.API) {
|
||||
func (p *HelloUserPlugin) OnActivate(api plugin.API) {
|
||||
// Just save api for later when we need to look up users.
|
||||
p.api = api
|
||||
}
|
||||
|
||||
func (p *MyPlugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
func (p *HelloUserPlugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if userId := r.Header.Get("Mattermost-User-Id"); userId == "" {
|
||||
// Our visitor is unauthenticated.
|
||||
fmt.Fprintf(w, "Hello, stranger!")
|
||||
@@ -33,6 +33,6 @@ func (p *MyPlugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// This example demonstrates a plugin that handles HTTP requests which respond by greeting the user
|
||||
// by name.
|
||||
func Example_plugin() {
|
||||
rpcplugin.Main(&MyPlugin{})
|
||||
func Example_helloUser() {
|
||||
rpcplugin.Main(&HelloUserPlugin{})
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package plugin_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/plugin/rpcplugin"
|
||||
)
|
||||
|
||||
type HelloWorldPlugin struct{}
|
||||
|
||||
func (p *HelloWorldPlugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Hello, world!")
|
||||
}
|
||||
|
||||
// This example demonstrates a plugin that handles HTTP requests which respond by greeting the
|
||||
// world.
|
||||
func Example_helloWorld() {
|
||||
rpcplugin.Main(&HelloWorldPlugin{})
|
||||
}
|
||||
+4
-4
@@ -7,10 +7,10 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Hooks represents an object that handles events for a plugin. Methods are likely to be added over
|
||||
// time, and plugins are not expected to implement all of them. Instead, plugins are expected to
|
||||
// implement a subset of them and pass an instance to plugin/rpcplugin.Main, which will take over
|
||||
// execution of the process and add default behaviors for missing hooks.
|
||||
// Methods from the Hooks interface can be used by a plugin to respond to events. Methods are likely
|
||||
// to be added over time, and plugins are not expected to implement all of them. Instead, plugins
|
||||
// are expected to implement a subset of them and pass an instance to plugin/rpcplugin.Main, which
|
||||
// will take over execution of the process and add default behaviors for missing hooks.
|
||||
type Hooks interface {
|
||||
// OnActivate is invoked when the plugin is activated. Implementations will usually want to save
|
||||
// the api argument for later use. Loading configuration for the first time is also a commonly
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
// The plugin package defines the primary interfaces for interacting with a Mattermost server: the
|
||||
// API and the hook interfaces.
|
||||
//
|
||||
// The API interface is used to perform actions. The Hook interface is used to respond to actions.
|
||||
//
|
||||
// Plugins should define a type that implements some of the methods from the Hook interface, then
|
||||
// pass an instance of that object into the rpcplugin package's Main function (See the HelloWorld
|
||||
// example.).
|
||||
package plugin
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
package plugin
|
||||
|
||||
// Supervisor provides the interface for an object that controls the execution of a plugin.
|
||||
// Supervisor provides the interface for an object that controls the execution of a plugin. This
|
||||
// type is only relevant to the server, and isn't used by the plugins themselves.
|
||||
type Supervisor interface {
|
||||
Start() error
|
||||
Stop() error
|
||||
|
||||
Reference in New Issue
Block a user