mirror of https://github.com/statping/statping
upgrades - plugins
parent
15c74bf4d2
commit
b53ad6e817
4
core.go
4
core.go
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/hunterlong/statup/plugin"
|
plg "plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Core struct {
|
type Core struct {
|
||||||
|
@ -11,7 +11,7 @@ type Core struct {
|
||||||
Key string
|
Key string
|
||||||
Secret string
|
Secret string
|
||||||
Version string
|
Version string
|
||||||
Plugins []*plugin.PluginInfo
|
Plugins []*plg.Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
func SelectCore() (*Core, error) {
|
func SelectCore() (*Core, error) {
|
||||||
|
|
5
main.go
5
main.go
|
@ -25,7 +25,7 @@ var (
|
||||||
jsBox *rice.Box
|
jsBox *rice.Box
|
||||||
tmplBox *rice.Box
|
tmplBox *rice.Box
|
||||||
setupMode bool
|
setupMode bool
|
||||||
allPlugins []*plugin.PluginInfo
|
allPlugins []plg.Plugin
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -110,9 +110,8 @@ func LoadPlugins() {
|
||||||
|
|
||||||
plugActions.OnLoad()
|
plugActions.OnLoad()
|
||||||
|
|
||||||
//allPlugins = append(allPlugins, plugActions.Plugin())
|
allPlugins = append(allPlugins, *plug)
|
||||||
}
|
}
|
||||||
core.Plugins = allPlugins
|
|
||||||
fmt.Printf("Loaded %v Plugins\n", len(allPlugins))
|
fmt.Printf("Loaded %v Plugins\n", len(allPlugins))
|
||||||
|
|
||||||
ForEachPlugin()
|
ForEachPlugin()
|
||||||
|
|
|
@ -11,12 +11,10 @@ var (
|
||||||
|
|
||||||
type PluginInfo struct {
|
type PluginInfo struct {
|
||||||
PluginActions
|
PluginActions
|
||||||
Name string
|
|
||||||
Creator string
|
Creator string
|
||||||
Version string
|
Version string
|
||||||
InstallSQL string
|
InstallSQL string
|
||||||
Form string
|
Form string
|
||||||
Routes []*Routing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Routing struct {
|
type Routing struct {
|
||||||
|
@ -26,7 +24,8 @@ type Routing struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PluginActions interface {
|
type PluginActions interface {
|
||||||
//Plugin() *PluginInfo
|
Name() string
|
||||||
|
Routines() Routing
|
||||||
SaveForm()
|
SaveForm()
|
||||||
OnInstall()
|
OnInstall()
|
||||||
OnUninstall()
|
OnUninstall()
|
||||||
|
|
BIN
plugins/slack.so
BIN
plugins/slack.so
Binary file not shown.
24
web.go
24
web.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
|
"github.com/hunterlong/statup/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -43,15 +44,22 @@ func RunHTTPServer() {
|
||||||
r.Handle("/plugins", http.HandlerFunc(PluginsHandler))
|
r.Handle("/plugins", http.HandlerFunc(PluginsHandler))
|
||||||
r.Handle("/help", http.HandlerFunc(HelpHandler))
|
r.Handle("/help", http.HandlerFunc(HelpHandler))
|
||||||
|
|
||||||
for _, plugin := range allPlugins {
|
for _, p := range allPlugins {
|
||||||
for _, route := range plugin.Routes {
|
symPlugin, _ := p.Lookup("Plugin")
|
||||||
path := fmt.Sprintf("/plugins/%v/%v", plugin.Name, route.URL)
|
var plugActions plugin.PluginActions
|
||||||
r.Handle(path, http.HandlerFunc(route.Handler)).Methods(route.Method)
|
plugActions, ok := symPlugin.(plugin.PluginActions)
|
||||||
fmt.Printf("Added Route %v for plugin %v\n", path, plugin.Name)
|
if !ok {
|
||||||
|
fmt.Printf("Plugin '%v' could not load correctly, error: %v\n", plugActions.Name(), "unexpected type from module symbol")
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
r.Handle("/plugins/install_"+plugin.Name, http.HandlerFunc(plugin.InstallPlugin)).Methods("GET")
|
fmt.Println(plugActions.Name())
|
||||||
r.Handle("/plugins/uninstall_"+plugin.Name, http.HandlerFunc(plugin.UninstallPlugin)).Methods("GET")
|
fmt.Println(plugActions.Routines())
|
||||||
r.Handle("/plugins/save_"+plugin.Name, http.HandlerFunc(plugin.SavePlugin)).Methods("POST")
|
//routes := plugActions.Routines()
|
||||||
|
//for _, route := range routes {
|
||||||
|
// path := fmt.Sprintf("/plugins/%v/%v", plugActions.Name(), route.URL)
|
||||||
|
// r.Handle(path, http.HandlerFunc(route.Handler)).Methods(route.Method)
|
||||||
|
// fmt.Printf("Added Route %v for plugin %v\n", path, plugActions.Name())
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
|
|
Loading…
Reference in New Issue