mirror of https://github.com/statping/statping
upgrades - plugins
parent
b53ad6e817
commit
b81b76881f
4
core.go
4
core.go
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/gorilla/sessions"
|
||||
plg "plugin"
|
||||
"github.com/hunterlong/statup/plugin"
|
||||
)
|
||||
|
||||
type Core struct {
|
||||
|
@ -11,7 +11,7 @@ type Core struct {
|
|||
Key string
|
||||
Secret string
|
||||
Version string
|
||||
Plugins []*plg.Plugin
|
||||
Plugins []plugin.Info
|
||||
}
|
||||
|
||||
func SelectCore() (*Core, error) {
|
||||
|
|
|
@ -3,10 +3,10 @@ package main
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/hunterlong/statup/plugin"
|
||||
_ "github.com/lib/pq"
|
||||
"math/rand"
|
||||
"time"
|
||||
"github.com/hunterlong/statup/plugin"
|
||||
)
|
||||
|
||||
func DbConnection() {
|
||||
|
|
|
@ -52,8 +52,6 @@
|
|||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
@ -22,20 +22,24 @@
|
|||
|
||||
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
|
||||
<a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true">Settings</a>
|
||||
{{ range .Plugins }}
|
||||
{{ range .Plugins }}
|
||||
<a class="nav-link text-capitalize" id="v-pills-{{.Name}}-tab" data-toggle="pill" href="#v-pills-{{.Name}}" role="tab" aria-controls="v-pills-profile" aria-selected="false">{{.Name}}</a>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<div class="tab-content" id="v-pills-tabContent">
|
||||
<div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">...</div>
|
||||
|
||||
{{ range .Plugins }}
|
||||
{{ range .Plugins }}
|
||||
<div class="tab-pane fade" id="v-pills-{{.Name}}" role="tabpanel" aria-labelledby="v-pills-{{.Name}}-tab">
|
||||
|
||||
<div class="tab-pane fade" id="v-pills-{{.Name}}" role="tabpanel" aria-labelledby="v-pills-{{.Name}}-tab">{{safe .Form }}</div>
|
||||
<form action="/plugins/{{.Name}}/save" method="POST">
|
||||
{{safe .Form }}
|
||||
</form>
|
||||
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
25
main.go
25
main.go
|
@ -6,25 +6,25 @@ import (
|
|||
"github.com/GeertJohan/go.rice"
|
||||
"github.com/go-yaml/yaml"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/hunterlong/statup/plugin"
|
||||
_ "github.com/lib/pq"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"io/ioutil"
|
||||
"github.com/hunterlong/statup/plugin"
|
||||
plg "plugin"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
db *sql.DB
|
||||
configs *Config
|
||||
core *Core
|
||||
store *sessions.CookieStore
|
||||
VERSION string
|
||||
sqlBox *rice.Box
|
||||
cssBox *rice.Box
|
||||
jsBox *rice.Box
|
||||
tmplBox *rice.Box
|
||||
setupMode bool
|
||||
db *sql.DB
|
||||
configs *Config
|
||||
core *Core
|
||||
store *sessions.CookieStore
|
||||
VERSION string
|
||||
sqlBox *rice.Box
|
||||
cssBox *rice.Box
|
||||
jsBox *rice.Box
|
||||
tmplBox *rice.Box
|
||||
setupMode bool
|
||||
allPlugins []plg.Plugin
|
||||
)
|
||||
|
||||
|
@ -51,7 +51,6 @@ func main() {
|
|||
mainProcess()
|
||||
}
|
||||
|
||||
|
||||
func mainProcess() {
|
||||
var err error
|
||||
DbConnection()
|
||||
|
@ -66,7 +65,6 @@ func mainProcess() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func ForEachPlugin() {
|
||||
if len(core.Plugins) > 0 {
|
||||
//for _, p := range core.Plugins {
|
||||
|
@ -75,7 +73,6 @@ func ForEachPlugin() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func LoadPlugins() {
|
||||
ForEachPlugin()
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"database/sql"
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var (
|
||||
DB *sql.DB
|
||||
DB *sql.DB
|
||||
AllPlugins []Info
|
||||
)
|
||||
|
||||
type PluginInfo struct {
|
||||
Info Info
|
||||
PluginActions
|
||||
Creator string
|
||||
Version string
|
||||
InstallSQL string
|
||||
Form string
|
||||
Add
|
||||
}
|
||||
|
||||
type Routing struct {
|
||||
|
@ -23,9 +23,22 @@ type Routing struct {
|
|||
Handler func(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
Name string
|
||||
Form string
|
||||
}
|
||||
|
||||
func (i Info) Template() *template.Template {
|
||||
t := template.New("form")
|
||||
temp, _ := t.Parse(i.Form)
|
||||
return temp
|
||||
}
|
||||
|
||||
type Add func(p PluginInfo)
|
||||
|
||||
type PluginActions interface {
|
||||
Name() string
|
||||
Routines() Routing
|
||||
GetInfo() Info
|
||||
Routes() []Routing
|
||||
SaveForm()
|
||||
OnInstall()
|
||||
OnUninstall()
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
[{
|
||||
"name": "slack",
|
||||
"description": "slack bot that send a message in a channel when server is down.",
|
||||
"repo": "https://github.com/hunterlong/statup_slack",
|
||||
"author": "Hunter Long",
|
||||
"namespace": "slack"
|
||||
}]
|
BIN
plugins/slack.so
BIN
plugins/slack.so
Binary file not shown.
32
web.go
32
web.go
|
@ -3,12 +3,12 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/hunterlong/statup/plugin"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/hunterlong/statup/plugin"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -46,22 +46,28 @@ func RunHTTPServer() {
|
|||
|
||||
for _, p := range allPlugins {
|
||||
symPlugin, _ := p.Lookup("Plugin")
|
||||
var plugActions plugin.PluginActions
|
||||
plugActions, ok := symPlugin.(plugin.PluginActions)
|
||||
var pluginObject plugin.PluginActions
|
||||
pluginObject, ok := symPlugin.(plugin.PluginActions)
|
||||
|
||||
info := pluginObject.GetInfo()
|
||||
|
||||
if !ok {
|
||||
fmt.Printf("Plugin '%v' could not load correctly, error: %v\n", plugActions.Name(), "unexpected type from module symbol")
|
||||
fmt.Printf("Plugin '%v' could not load correctly, error: %v\n", info.Name, "unexpected type from module symbol")
|
||||
continue
|
||||
}
|
||||
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())
|
||||
//}
|
||||
|
||||
plugin.AllPlugins = append(plugin.AllPlugins, info)
|
||||
|
||||
for _, route := range pluginObject.Routes() {
|
||||
path := fmt.Sprintf("/plugins/%v/%v", info.Name, route.URL)
|
||||
r.Handle(path, http.HandlerFunc(route.Handler)).Methods(route.Method)
|
||||
fmt.Printf("Added Route %v for plugin %v\n", path, info.Name)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
core.Plugins = plugin.AllPlugins
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: "0.0.0.0:8080",
|
||||
WriteTimeout: time.Second * 15,
|
||||
|
|
Loading…
Reference in New Issue