mirror of https://github.com/statping/statping
upgrades - plugins
parent
dfcdbcffe1
commit
4df559efc7
|
@ -6,12 +6,17 @@ import (
|
|||
|
||||
var (
|
||||
pluginRoutes []*plugins.Routing
|
||||
allPlugins []*plugins.Plugin
|
||||
)
|
||||
|
||||
func InitPluginsDatabase() {
|
||||
plugins.InitDB(db)
|
||||
}
|
||||
|
||||
func SetAuthorized() {
|
||||
|
||||
}
|
||||
|
||||
func Routes() []*plugins.Routing {
|
||||
return plugins.PluginRoutes
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
yooyyo
|
|
@ -3,24 +3,45 @@ package plugins
|
|||
import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
db *sql.DB
|
||||
PluginRoutes []*Routing
|
||||
Plugins []*Plugin
|
||||
)
|
||||
|
||||
type Plugin struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type Routing struct {
|
||||
URL string
|
||||
Method string
|
||||
Handler func(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
|
||||
func Add(name string) {
|
||||
plugin := &Plugin{name}
|
||||
Plugins = append(Plugins, plugin)
|
||||
}
|
||||
|
||||
func AddRoute(url string, method string, handle func(http.ResponseWriter, *http.Request)) {
|
||||
route := &Routing{url, method, handle}
|
||||
PluginRoutes = append(PluginRoutes, route)
|
||||
}
|
||||
|
||||
func Authenticated(r *http.Request) bool {
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func log(msg... string) {
|
||||
fmt.Println(" @plugins: ",msg)
|
||||
}
|
||||
|
||||
func InitDB(database *sql.DB) {
|
||||
db = database
|
||||
}
|
|
@ -1,30 +1,69 @@
|
|||
package plugins
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
SLACK_TABLE = "plugin_slack"
|
||||
)
|
||||
|
||||
func init() {
|
||||
AddRoute("save_slack", "POST", SaveIt)
|
||||
AddRoute("create_slack", "GET", Create)
|
||||
Add("slack")
|
||||
AddRoute("install_slack", "GET", InstallSlack)
|
||||
AddRoute("uninstall_slack", "GET", UninstallSlack)
|
||||
AddRoute("save_slack", "POST", SaveSettings)
|
||||
}
|
||||
|
||||
func SaveIt(w http.ResponseWriter, r *http.Request) {
|
||||
type Slack struct {
|
||||
Key string
|
||||
Secret string
|
||||
Enabled bool
|
||||
Channel string
|
||||
}
|
||||
|
||||
func InstallSlack(w http.ResponseWriter, r *http.Request) {
|
||||
CreateTable()
|
||||
http.Redirect(w, r, "/plugins", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func Create(w http.ResponseWriter, r *http.Request) {
|
||||
CreateTable()
|
||||
func UninstallSlack(w http.ResponseWriter, r *http.Request) {
|
||||
DropTable()
|
||||
http.Redirect(w, r, "/plugins", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
func SaveSettings(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
key := r.PostForm.Get("key")
|
||||
secret := r.PostForm.Get("secret")
|
||||
enabled, _ := strconv.ParseBool(r.PostForm.Get("enabled"))
|
||||
channel := r.PostForm.Get("channel")
|
||||
|
||||
slack := &Slack {
|
||||
key,
|
||||
secret,
|
||||
enabled,
|
||||
channel,
|
||||
}
|
||||
|
||||
slack.UpdateTable()
|
||||
|
||||
http.Redirect(w, r, "/plugins", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
|
||||
func CreateTable() {
|
||||
sql := "CREATE TABLE slack (enabled BOOLEAN, api_key text, api_key text, channel text);"
|
||||
sql := "CREATE TABLE "+SLACK_TABLE+" (enabled BOOLEAN, api_key text, api_secret text, channel text);"
|
||||
db.QueryRow(sql).Scan()
|
||||
}
|
||||
|
||||
func (s *Slack) UpdateTable() {
|
||||
sql := "CREATE TABLE "+SLACK_TABLE+" (enabled BOOLEAN, api_key text, api_key text, channel text);"
|
||||
db.QueryRow(sql).Scan()
|
||||
}
|
||||
|
||||
func DropTable() {
|
||||
sql := "DROP TABLE slack;"
|
||||
sql := "DROP TABLE "+SLACK_TABLE+";"
|
||||
db.QueryRow(sql).Scan()
|
||||
}
|
||||
|
||||
func UpdateDatabase() {
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue