more plugin doc updates (#7767)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
71dd21ef3d
Коммит
d2cff9b77c
@@ -7,8 +7,10 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// API implementations can be used to retrieve data or perform actions on behalf of the plugin. Most
|
// The API can be used to retrieve data or perform actions on behalf of the plugin. Most methods
|
||||||
// methods have direct counterparts in the REST API and very similar behavior.
|
// 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 {
|
type API interface {
|
||||||
// LoadPluginConfiguration loads the plugin's configuration. dest should be a pointer to a
|
// LoadPluginConfiguration loads the plugin's configuration. dest should be a pointer to a
|
||||||
// struct that the configuration JSON can be unmarshalled to.
|
// struct that the configuration JSON can be unmarshalled to.
|
||||||
|
|||||||
@@ -8,16 +8,16 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/plugin/rpcplugin"
|
"github.com/mattermost/mattermost-server/plugin/rpcplugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MyPlugin struct {
|
type HelloUserPlugin struct {
|
||||||
api plugin.API
|
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.
|
// Just save api for later when we need to look up users.
|
||||||
p.api = api
|
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 == "" {
|
if userId := r.Header.Get("Mattermost-User-Id"); userId == "" {
|
||||||
// Our visitor is unauthenticated.
|
// Our visitor is unauthenticated.
|
||||||
fmt.Fprintf(w, "Hello, stranger!")
|
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
|
// This example demonstrates a plugin that handles HTTP requests which respond by greeting the user
|
||||||
// by name.
|
// by name.
|
||||||
func Example_plugin() {
|
func Example_helloUser() {
|
||||||
rpcplugin.Main(&MyPlugin{})
|
rpcplugin.Main(&HelloUserPlugin{})
|
||||||
}
|
}
|
||||||
20
plugin/example_hello_world_test.go
Обычный файл
20
plugin/example_hello_world_test.go
Обычный файл
@@ -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{})
|
||||||
|
}
|
||||||
@@ -7,10 +7,10 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Hooks represents an object that handles events for a plugin. Methods are likely to be added over
|
// Methods from the Hooks interface can be used by a plugin to respond to events. Methods are likely
|
||||||
// time, and plugins are not expected to implement all of them. Instead, plugins are expected to
|
// to be added over time, and plugins are not expected to implement all of them. Instead, plugins
|
||||||
// implement a subset of them and pass an instance to plugin/rpcplugin.Main, which will take over
|
// are expected to implement a subset of them and pass an instance to plugin/rpcplugin.Main, which
|
||||||
// execution of the process and add default behaviors for missing hooks.
|
// will take over execution of the process and add default behaviors for missing hooks.
|
||||||
type Hooks interface {
|
type Hooks interface {
|
||||||
// OnActivate is invoked when the plugin is activated. Implementations will usually want to save
|
// 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
|
// the api argument for later use. Loading configuration for the first time is also a commonly
|
||||||
|
|||||||
12
plugin/plugin.go
Обычный файл
12
plugin/plugin.go
Обычный файл
@@ -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
|
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 {
|
type Supervisor interface {
|
||||||
Start() error
|
Start() error
|
||||||
Stop() error
|
Stop() error
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user