diff --git a/Statup-Plugins.md b/Statup-Plugins.md index b6f0053..1812bd0 100644 --- a/Statup-Plugins.md +++ b/Statup-Plugins.md @@ -1,12 +1,22 @@ -Since Statup is built in Go Language we can use the go plugin feature to create dynamic plugins that run on load. Statup has an event anytime anything happens, you can create your own plugins and do any type of function. - -## Statup Plugin Package -To implement your own ideas into Statup, either do a git push request or use it has a plugin using the [statup/plugin](https://github.com/hunterlong/statup/blob/master/plugin/main.go) package. +Since Statup is built in Go Language we can use the go plugin feature to create dynamic plugins that run on load. Statup has an event anytime anything happens, you can create your own plugins and do any type of function. To implement your own ideas into Statup, use the plugin using the [statup/plugin](https://github.com/hunterlong/statup/blob/master/plugin/main.go) package. ``` go get github.com/hunterlong/statup/plugin ``` -## Plugin Interface +## Example Plugin +Start off with the [Example Statup Plugin](https://github.com/hunterlong/statup_plugin) that includes all the interfaces and some custom options for you to expand on. You can include any type of function in your own plugin! + +## Building Plugins +Plugins don't need a push request and they can be private! You'll need to compile your plugin to the Golang `.so` binary format. Once you've built your plugin, insert it into the `plugins` folder in your Statup directory and reboot the application. Clone the [Example Statup Plugin](https://github.com/hunterlong/statup_plugin) repo and try to build it yourself! + +```bash +git clone https://github.com/hunterlong/statup_plugin +cd statup-plugin +go build -buildmode=plugin -o example.so +``` + +## Statup Plugin Interface +Please remember Golang plugin's are very new and Statup plugin package may change and 'could' brake your plugin. ```go type PluginActions interface { GetInfo() Info @@ -30,11 +40,39 @@ type PluginActions interface { } ``` +## Event Parameters +All event interfaces for the Statup Plugin will return a `map[string]interface{}` type, this is because the plugin package will most likely update and change in the future, but using this type will allow your plugin to continue even after updates. + ## Example of an Event -Knowing what happens during an event is important for your plugin. For example, lets have an event that echo something when a service has a Failure status being issued. +Knowing what happens during an event is important for your plugin. For example, lets have an event that echo something when a service has a Failure status being issued. Checkout some example below to see how this golang plugin action works. + +```go +func (p pkg) OnSuccess(data map[string]interface{}) { + fmt.Println("Statup Example Plugin received a successful service hit! ") + fmt.Println("Name: ", data["Name"]) + fmt.Println("Domain: ", data["Domain"]) + fmt.Println("Method: ", data["Method"]) + fmt.Println("Latency: ", data["Latency"]) +} +``` +###### OnSuccess is fired every time a service has check it be online + ```go func OnFailure(service map[string]interface{}) { fmt.Println("oh no! an event is failing right now! do something!") fmt.Println(service) } -``` \ No newline at end of file +``` +###### OnFailure is fired every time a service is failing + +```go +func (p pkg) OnLoad(db sqlbuilder.Database) { + fmt.Println("=============================================================") + fmt.Printf(" Statup Example Plugin Loaded using %v database\n", db.Name()) + fmt.Println("=============================================================") +} +``` +###### OnLoad is fired after plugin is loaded into the environment + +## Custom HTTP Routes +Plugin's can include their own HTTP route to accept GET/POST requests. \ No newline at end of file