Newer
Older
bathroom-plugin / mattermost / server / bathroom.go
package main

import (
	"fmt"
	"net/http"
	"github.com/mattermost/mattermost-server/plugin"
	"github.com/pkg/errors"
	"sync"
)

type Config struct {
	NumDoors uint8
	WatchPath string
}

type HelloWorldPlugin struct {
	plugin.MattermostPlugin
	config *Config
	configLock sync.RWMutex
}

func (p *HelloWorldPlugin) Init() *HelloWorldPlugin {
	p.config = &Config{NumDoors: 1, WatchPath: "./"}

	return p;
}

func (p *HelloWorldPlugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "Hello, world!")
}

func (p *HelloWorldPlugin) OnConfigurationChange() error {
	p.configLock.Lock()
	defer p.configLock.Unlock()

	if err := p.API.LoadPluginConfiguration(p.config); err != nil {
		return errors.Wrap(err, "failed to load configuration")
	}

	p.API.LogInfo(fmt.Sprintf("Config: %d %s", p.config.NumDoors, p.config.WatchPath))

	return nil
}



func (p *HelloWorldPlugin) OnActivate() error {

	return nil
}

// This example demonstrates a plugin that handles HTTP requests which respond by greeting the
// world.
func main() {
	plugin.ClientMain((&HelloWorldPlugin{}).Init())
}