statping/plugin/main.go

108 lines
1.6 KiB
Go
Raw Normal View History

2018-06-14 01:19:00 +00:00
package plugin
import (
2018-06-14 06:38:15 +00:00
"database/sql"
"fmt"
2018-06-14 01:19:00 +00:00
"net/http"
"time"
)
2018-06-14 06:38:15 +00:00
//
// STATUP PLUGIN INTERFACE
//
// v0.1
//
// https://statup.io
//
var (
DB *sql.DB
)
func SetDatabase(database *sql.DB) {
DB = database
}
func Throw(err error) {
fmt.Println(err)
}
type PluginInfo struct {
Info Info
PluginActions
}
2018-06-14 01:19:00 +00:00
type PluginActions interface {
GetInfo() Info
2018-06-14 06:38:15 +00:00
SetInfo(map[string]string) Info
2018-06-14 01:19:00 +00:00
Routes() []Routing
OnSave(map[string]string)
2018-06-14 06:38:15 +00:00
OnFailure(*Service)
OnSuccess(*Service)
OnSettingsSaved(map[string]string)
OnNewUser(*User)
OnNewService(*Service)
OnUpdatedService(*Service)
OnDeletedService(*Service)
2018-06-14 01:19:00 +00:00
OnInstall()
OnUninstall()
OnShutdown()
OnLoad()
OnBeforeRequest()
OnAfterRequest()
}
2018-06-14 06:38:15 +00:00
type User struct {
Id int64
Username string
Password string
Email string
}
2018-06-14 01:19:00 +00:00
type Service struct {
Id int64
Name string
Domain string
Expected string
ExpectedStatus int
Interval int
Method string
Port int
CreatedAt time.Time
Data string
Online bool
Latency float64
Online24Hours float32
AvgResponse string
TotalUptime string
Failures []*Failure
}
type Failure struct {
Id int
Issue string
Service int
CreatedAt time.Time
Ago string
}
type Routing struct {
URL string
Method string
Handler func(http.ResponseWriter, *http.Request)
}
type Info struct {
Name string
Description string
2018-06-14 06:38:15 +00:00
Form []*FormElement
2018-06-14 01:19:00 +00:00
}
type FormElement struct {
Name string
Description string
2018-06-14 06:38:15 +00:00
InputName string
InputType string
Value string
2018-06-14 01:19:00 +00:00
}