diff --git a/mattermost/server/bathroom-linux-amd64 b/mattermost/server/bathroom-linux-amd64 index ff8c417..69d6958 100755 --- a/mattermost/server/bathroom-linux-amd64 +++ b/mattermost/server/bathroom-linux-amd64 Binary files differ diff --git a/mattermost/server/bathroom-linux-amd64 b/mattermost/server/bathroom-linux-amd64 index ff8c417..69d6958 100755 --- a/mattermost/server/bathroom-linux-amd64 +++ b/mattermost/server/bathroom-linux-amd64 Binary files differ diff --git a/mattermost/server/bathroom.go b/mattermost/server/bathroom.go index 05f8544..04509ba 100644 --- a/mattermost/server/bathroom.go +++ b/mattermost/server/bathroom.go @@ -3,20 +3,54 @@ 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{}) + plugin.ClientMain((&HelloWorldPlugin{}).Init()) } diff --git a/mattermost/server/bathroom-linux-amd64 b/mattermost/server/bathroom-linux-amd64 index ff8c417..69d6958 100755 --- a/mattermost/server/bathroom-linux-amd64 +++ b/mattermost/server/bathroom-linux-amd64 Binary files differ diff --git a/mattermost/server/bathroom.go b/mattermost/server/bathroom.go index 05f8544..04509ba 100644 --- a/mattermost/server/bathroom.go +++ b/mattermost/server/bathroom.go @@ -3,20 +3,54 @@ 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{}) + plugin.ClientMain((&HelloWorldPlugin{}).Init()) } diff --git a/mattermost/server/bathroom.tar.gz b/mattermost/server/bathroom.tar.gz new file mode 100644 index 0000000..6781b7e --- /dev/null +++ b/mattermost/server/bathroom.tar.gz Binary files differ diff --git a/mattermost/server/bathroom-linux-amd64 b/mattermost/server/bathroom-linux-amd64 index ff8c417..69d6958 100755 --- a/mattermost/server/bathroom-linux-amd64 +++ b/mattermost/server/bathroom-linux-amd64 Binary files differ diff --git a/mattermost/server/bathroom.go b/mattermost/server/bathroom.go index 05f8544..04509ba 100644 --- a/mattermost/server/bathroom.go +++ b/mattermost/server/bathroom.go @@ -3,20 +3,54 @@ 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{}) + plugin.ClientMain((&HelloWorldPlugin{}).Init()) } diff --git a/mattermost/server/bathroom.tar.gz b/mattermost/server/bathroom.tar.gz new file mode 100644 index 0000000..6781b7e --- /dev/null +++ b/mattermost/server/bathroom.tar.gz Binary files differ diff --git a/mattermost/server/package.sh b/mattermost/server/package.sh new file mode 100755 index 0000000..c8ce874 --- /dev/null +++ b/mattermost/server/package.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash + +tar -czvf bathroom.tar.gz bathroom-linux-amd64 plugin.json diff --git a/mattermost/server/bathroom-linux-amd64 b/mattermost/server/bathroom-linux-amd64 index ff8c417..69d6958 100755 --- a/mattermost/server/bathroom-linux-amd64 +++ b/mattermost/server/bathroom-linux-amd64 Binary files differ diff --git a/mattermost/server/bathroom.go b/mattermost/server/bathroom.go index 05f8544..04509ba 100644 --- a/mattermost/server/bathroom.go +++ b/mattermost/server/bathroom.go @@ -3,20 +3,54 @@ 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{}) + plugin.ClientMain((&HelloWorldPlugin{}).Init()) } diff --git a/mattermost/server/bathroom.tar.gz b/mattermost/server/bathroom.tar.gz new file mode 100644 index 0000000..6781b7e --- /dev/null +++ b/mattermost/server/bathroom.tar.gz Binary files differ diff --git a/mattermost/server/package.sh b/mattermost/server/package.sh new file mode 100755 index 0000000..c8ce874 --- /dev/null +++ b/mattermost/server/package.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash + +tar -czvf bathroom.tar.gz bathroom-linux-amd64 plugin.json diff --git a/mattermost/server/plugin.json b/mattermost/server/plugin.json index 796cc21..e5c6549 100644 --- a/mattermost/server/plugin.json +++ b/mattermost/server/plugin.json @@ -1,7 +1,7 @@ { - "id": "com.mattermost.server-hello-world", - "name": "Hello World", + "id": "com.mattermost.bathroom", + "name": "Bathroom Monitor", "server": { - "executable": "plugin-linux-amd64" + "executable": "bathroom-linux-amd64" } } diff --git a/mattermost/server/bathroom-linux-amd64 b/mattermost/server/bathroom-linux-amd64 index ff8c417..69d6958 100755 --- a/mattermost/server/bathroom-linux-amd64 +++ b/mattermost/server/bathroom-linux-amd64 Binary files differ diff --git a/mattermost/server/bathroom.go b/mattermost/server/bathroom.go index 05f8544..04509ba 100644 --- a/mattermost/server/bathroom.go +++ b/mattermost/server/bathroom.go @@ -3,20 +3,54 @@ 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{}) + plugin.ClientMain((&HelloWorldPlugin{}).Init()) } diff --git a/mattermost/server/bathroom.tar.gz b/mattermost/server/bathroom.tar.gz new file mode 100644 index 0000000..6781b7e --- /dev/null +++ b/mattermost/server/bathroom.tar.gz Binary files differ diff --git a/mattermost/server/package.sh b/mattermost/server/package.sh new file mode 100755 index 0000000..c8ce874 --- /dev/null +++ b/mattermost/server/package.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash + +tar -czvf bathroom.tar.gz bathroom-linux-amd64 plugin.json diff --git a/mattermost/server/plugin.json b/mattermost/server/plugin.json index 796cc21..e5c6549 100644 --- a/mattermost/server/plugin.json +++ b/mattermost/server/plugin.json @@ -1,7 +1,7 @@ { - "id": "com.mattermost.server-hello-world", - "name": "Hello World", + "id": "com.mattermost.bathroom", + "name": "Bathroom Monitor", "server": { - "executable": "plugin-linux-amd64" + "executable": "bathroom-linux-amd64" } } diff --git a/mattermost/server/setup.sh b/mattermost/server/setup.sh index db2f519..f2aa708 100755 --- a/mattermost/server/setup.sh +++ b/mattermost/server/setup.sh @@ -3,3 +3,4 @@ go get -u github.com/mattermost/mattermost-server go get -u golang.org/x/sys/... go get -u github.com/fsnotify/fsnotify +go get -u github.com/pkg/errors diff --git a/mattermost/server/bathroom-linux-amd64 b/mattermost/server/bathroom-linux-amd64 index ff8c417..69d6958 100755 --- a/mattermost/server/bathroom-linux-amd64 +++ b/mattermost/server/bathroom-linux-amd64 Binary files differ diff --git a/mattermost/server/bathroom.go b/mattermost/server/bathroom.go index 05f8544..04509ba 100644 --- a/mattermost/server/bathroom.go +++ b/mattermost/server/bathroom.go @@ -3,20 +3,54 @@ 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{}) + plugin.ClientMain((&HelloWorldPlugin{}).Init()) } diff --git a/mattermost/server/bathroom.tar.gz b/mattermost/server/bathroom.tar.gz new file mode 100644 index 0000000..6781b7e --- /dev/null +++ b/mattermost/server/bathroom.tar.gz Binary files differ diff --git a/mattermost/server/package.sh b/mattermost/server/package.sh new file mode 100755 index 0000000..c8ce874 --- /dev/null +++ b/mattermost/server/package.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash + +tar -czvf bathroom.tar.gz bathroom-linux-amd64 plugin.json diff --git a/mattermost/server/plugin.json b/mattermost/server/plugin.json index 796cc21..e5c6549 100644 --- a/mattermost/server/plugin.json +++ b/mattermost/server/plugin.json @@ -1,7 +1,7 @@ { - "id": "com.mattermost.server-hello-world", - "name": "Hello World", + "id": "com.mattermost.bathroom", + "name": "Bathroom Monitor", "server": { - "executable": "plugin-linux-amd64" + "executable": "bathroom-linux-amd64" } } diff --git a/mattermost/server/setup.sh b/mattermost/server/setup.sh index db2f519..f2aa708 100755 --- a/mattermost/server/setup.sh +++ b/mattermost/server/setup.sh @@ -3,3 +3,4 @@ go get -u github.com/mattermost/mattermost-server go get -u golang.org/x/sys/... go get -u github.com/fsnotify/fsnotify +go get -u github.com/pkg/errors diff --git a/mattermost/server/test.go b/mattermost/server/test.go new file mode 100644 index 0000000..781c514 --- /dev/null +++ b/mattermost/server/test.go @@ -0,0 +1,41 @@ +package main + +import ( + "log" + "github.com/fsnotify/fsnotify" +) + +func main() { + watcher, err := fsnotify.NewWatcher() + if err != nil { + log.Fatal(err) + } + defer watcher.Close() + + done := make(chan bool) + go func() { + for { + select { + case event, ok := <-watcher.Events: + if !ok { + return + } + log.Println("event:", event) + if event.Op&fsnotify.Write == fsnotify.Write { + log.Println("modified file:", event.Name) + } + case err, ok := <-watcher.Errors: + if !ok { + return + } + log.Println("error:", err) + } + } + }() + + err = watcher.Add("./watch") + if err != nil { + log.Fatal(err) + } + <-done +}