mirror of https://github.com/statping/statping
Updated Statup Plugins (markdown)
parent
20bb5a69a8
commit
3694a50f6b
|
@ -13,6 +13,10 @@ Start off with the [Example Statup Plugin](https://github.com/hunterlong/statup_
|
|||
## 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!
|
||||
|
||||
#### Build Requirements
|
||||
- You must have `main.go`
|
||||
- You must create the Plugin variable on `init()`
|
||||
|
||||
```bash
|
||||
git clone https://github.com/hunterlong/statup_plugin
|
||||
cd statup-plugin
|
||||
|
@ -26,13 +30,13 @@ Statup includes a couple tools to help you on your Plugin journey, you can use `
|
|||
statup test plugins
|
||||
```
|
||||
<p align="center">
|
||||
<img width="95%" src="https://s3-us-west-2.amazonaws.com/gitimgs/statupplugin2.png">
|
||||
<img width="75%" src="https://s3-us-west-2.amazonaws.com/gitimgs/statupplugintester.png">
|
||||
</p>
|
||||
|
||||
Your plugin should be able to parse and receive events before distributing it. The test tools creates a temporary database (SQLite) that your plugin can interact with. Statup uses [upper.io/db.v3](https://upper.io/db.v3) for database interactions. The database is passed to your plugin `OnLoad(db sqlbuilder.Database)`, so you can use the `db` variable passed here.
|
||||
|
||||
## Statup Plugin Interface
|
||||
Please remember Golang plugin's are very new and Statup plugin package may change and 'could' brake your plugin.
|
||||
Please remember Golang plugin's are very new and Statup plugin package may change and 'could' brake your plugin. Checkout the [statup/plugin package](https://github.com/hunterlong/statup/blob/master/plugin/main.go) to see the most current interfaces.
|
||||
```go
|
||||
type PluginActions interface {
|
||||
GetInfo() Info
|
||||
|
@ -90,9 +94,41 @@ func (p pkg) OnLoad(db sqlbuilder.Database) {
|
|||
```
|
||||
###### OnLoad is fired after plugin is loaded into the environment
|
||||
|
||||
|
||||
## Interacting with Database
|
||||
The Example Statup Plugin includes a variable `Database` that will allow you to interact with the Statup database. Checkout [database.go](https://github.com/hunterlong/statup_plugin/blob/master/database.go) to see a full example of Create, Read, Update and then Deleting a custom Communication entry into the database.
|
||||
```go
|
||||
// Insert a new communication into database
|
||||
// once inserted, return the Communication
|
||||
func (c *Communication) Create() *Communication {
|
||||
uuid, err := CommunicationTable().Insert(c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.Id = uuid.(int64)
|
||||
return c
|
||||
}
|
||||
```
|
||||
|
||||
## Custom HTTP Routes
|
||||
Plugin's can include their own HTTP route to accept GET/POST requests.
|
||||
Plugin's can include their own HTTP route to accept GET/POST requests. Route are loaded after Statup loads all of it's Routes. Checkout [routes.go](https://github.com/hunterlong/statup_plugin/blob/master/routes.go) on the example plugin to see a full example of how to use it.
|
||||
```go
|
||||
// You must have a Routes() method in your plugin
|
||||
func (p *pkg) Routes() []plugin.Routing {
|
||||
return []plugin.Routing{{
|
||||
URL: "hello",
|
||||
Method: "GET",
|
||||
Handler: CustomInfoHandler,
|
||||
}}
|
||||
}
|
||||
|
||||
// This is the HTTP handler for the '/hello' URL created above
|
||||
func CustomInfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintln(w, "Oh Wow!!! This is cool...")
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Plugin To-Do List
|
||||
- [ ] Ability to read/write to database
|
||||
- [ ] Ability to includes assets like jpg, json, etc
|
Loading…
Reference in New Issue