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 (
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/hunterlong/statup/plugin"
|
||||
plg "plugin"
|
||||
)
|
||||
|
||||
type Core struct {
|
||||
|
@ -11,7 +11,7 @@ type Core struct {
|
|||
Key string
|
||||
Secret string
|
||||
Version string
|
||||
Plugins []*plugin.PluginInfo
|
||||
Plugins []*plg.Plugin
|
||||
}
|
||||
|
||||
func SelectCore() (*Core, error) {
|
||||
|
|
5
main.go
5
main.go
|
@ -25,7 +25,7 @@ var (
|
|||
jsBox *rice.Box
|
||||
tmplBox *rice.Box
|
||||
setupMode bool
|
||||
allPlugins []*plugin.PluginInfo
|
||||
allPlugins []plg.Plugin
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
@ -110,9 +110,8 @@ func LoadPlugins() {
|
|||
|
||||
plugActions.OnLoad()
|
||||
|
||||
//allPlugins = append(allPlugins, plugActions.Plugin())
|
||||
allPlugins = append(allPlugins, *plug)
|
||||
}
|
||||
core.Plugins = allPlugins
|
||||
fmt.Printf("Loaded %v Plugins\n", len(allPlugins))
|
||||
|
||||
ForEachPlugin()
|
||||
|
|
|
@ -11,12 +11,10 @@ var (
|
|||
|
||||
type PluginInfo struct {
|
||||
PluginActions
|
||||
Name string
|
||||
Creator string
|
||||
Version string
|
||||
InstallSQL string
|
||||
Form string
|
||||
Routes []*Routing
|
||||
}
|
||||
|
||||
type Routing struct {
|
||||
|
@ -26,7 +24,8 @@ type Routing struct {
|
|||
}
|
||||
|
||||
type PluginActions interface {
|
||||
//Plugin() *PluginInfo
|
||||
Name() string
|
||||
Routines() Routing
|
||||
SaveForm()
|
||||
OnInstall()
|
||||
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"
|
||||
"time"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/hunterlong/statup/plugin"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -43,15 +44,22 @@ func RunHTTPServer() {
|
|||
r.Handle("/plugins", http.HandlerFunc(PluginsHandler))
|
||||
r.Handle("/help", http.HandlerFunc(HelpHandler))
|
||||
|
||||
for _, plugin := range allPlugins {
|
||||
for _, route := range plugin.Routes {
|
||||
path := fmt.Sprintf("/plugins/%v/%v", plugin.Name, route.URL)
|
||||
r.Handle(path, http.HandlerFunc(route.Handler)).Methods(route.Method)
|
||||
fmt.Printf("Added Route %v for plugin %v\n", path, plugin.Name)
|
||||
for _, p := range allPlugins {
|
||||
symPlugin, _ := p.Lookup("Plugin")
|
||||
var plugActions plugin.PluginActions
|
||||
plugActions, ok := symPlugin.(plugin.PluginActions)
|
||||
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")
|
||||
r.Handle("/plugins/uninstall_"+plugin.Name, http.HandlerFunc(plugin.UninstallPlugin)).Methods("GET")
|
||||
r.Handle("/plugins/save_"+plugin.Name, http.HandlerFunc(plugin.SavePlugin)).Methods("POST")
|
||||
fmt.Println(plugActions.Name())
|
||||
fmt.Println(plugActions.Routines())
|
||||
//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{
|
||||
|
|
Loading…
Reference in New Issue