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 (
|
import (
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
plg "plugin"
|
"github.com/hunterlong/statup/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 []*plg.Plugin
|
Plugins []plugin.Info
|
||||||
}
|
}
|
||||||
|
|
||||||
func SelectCore() (*Core, error) {
|
func SelectCore() (*Core, error) {
|
||||||
|
|
|
@ -3,10 +3,10 @@ package main
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/hunterlong/statup/plugin"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
"github.com/hunterlong/statup/plugin"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func DbConnection() {
|
func DbConnection() {
|
||||||
|
|
|
@ -52,8 +52,6 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,13 @@
|
||||||
<div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">...</div>
|
<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>
|
||||||
|
|
||||||
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
5
main.go
5
main.go
|
@ -6,10 +6,10 @@ import (
|
||||||
"github.com/GeertJohan/go.rice"
|
"github.com/GeertJohan/go.rice"
|
||||||
"github.com/go-yaml/yaml"
|
"github.com/go-yaml/yaml"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
|
"github.com/hunterlong/statup/plugin"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"github.com/hunterlong/statup/plugin"
|
|
||||||
plg "plugin"
|
plg "plugin"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -51,7 +51,6 @@ func main() {
|
||||||
mainProcess()
|
mainProcess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func mainProcess() {
|
func mainProcess() {
|
||||||
var err error
|
var err error
|
||||||
DbConnection()
|
DbConnection()
|
||||||
|
@ -66,7 +65,6 @@ func mainProcess() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func ForEachPlugin() {
|
func ForEachPlugin() {
|
||||||
if len(core.Plugins) > 0 {
|
if len(core.Plugins) > 0 {
|
||||||
//for _, p := range core.Plugins {
|
//for _, p := range core.Plugins {
|
||||||
|
@ -75,7 +73,6 @@ func ForEachPlugin() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func LoadPlugins() {
|
func LoadPlugins() {
|
||||||
ForEachPlugin()
|
ForEachPlugin()
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"html/template"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DB *sql.DB
|
DB *sql.DB
|
||||||
|
AllPlugins []Info
|
||||||
)
|
)
|
||||||
|
|
||||||
type PluginInfo struct {
|
type PluginInfo struct {
|
||||||
|
Info Info
|
||||||
PluginActions
|
PluginActions
|
||||||
Creator string
|
Add
|
||||||
Version string
|
|
||||||
InstallSQL string
|
|
||||||
Form string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Routing struct {
|
type Routing struct {
|
||||||
|
@ -23,9 +23,22 @@ type Routing struct {
|
||||||
Handler func(http.ResponseWriter, *http.Request)
|
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 {
|
type PluginActions interface {
|
||||||
Name() string
|
GetInfo() Info
|
||||||
Routines() Routing
|
Routes() []Routing
|
||||||
SaveForm()
|
SaveForm()
|
||||||
OnInstall()
|
OnInstall()
|
||||||
OnUninstall()
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/gorilla/sessions"
|
||||||
|
"github.com/hunterlong/statup/plugin"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
"github.com/gorilla/sessions"
|
|
||||||
"github.com/hunterlong/statup/plugin"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -46,22 +46,28 @@ func RunHTTPServer() {
|
||||||
|
|
||||||
for _, p := range allPlugins {
|
for _, p := range allPlugins {
|
||||||
symPlugin, _ := p.Lookup("Plugin")
|
symPlugin, _ := p.Lookup("Plugin")
|
||||||
var plugActions plugin.PluginActions
|
var pluginObject plugin.PluginActions
|
||||||
plugActions, ok := symPlugin.(plugin.PluginActions)
|
pluginObject, ok := symPlugin.(plugin.PluginActions)
|
||||||
|
|
||||||
|
info := pluginObject.GetInfo()
|
||||||
|
|
||||||
if !ok {
|
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
|
continue
|
||||||
}
|
}
|
||||||
fmt.Println(plugActions.Name())
|
|
||||||
fmt.Println(plugActions.Routines())
|
plugin.AllPlugins = append(plugin.AllPlugins, info)
|
||||||
//routes := plugActions.Routines()
|
|
||||||
//for _, route := range routes {
|
for _, route := range pluginObject.Routes() {
|
||||||
// path := fmt.Sprintf("/plugins/%v/%v", plugActions.Name(), route.URL)
|
path := fmt.Sprintf("/plugins/%v/%v", info.Name, route.URL)
|
||||||
// r.Handle(path, http.HandlerFunc(route.Handler)).Methods(route.Method)
|
r.Handle(path, http.HandlerFunc(route.Handler)).Methods(route.Method)
|
||||||
// fmt.Printf("Added Route %v for plugin %v\n", path, plugActions.Name())
|
fmt.Printf("Added Route %v for plugin %v\n", path, info.Name)
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
core.Plugins = plugin.AllPlugins
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: "0.0.0.0:8080",
|
Addr: "0.0.0.0:8080",
|
||||||
WriteTimeout: time.Second * 15,
|
WriteTimeout: time.Second * 15,
|
||||||
|
|
Loading…
Reference in New Issue