diff --git a/core.go b/core.go index e91266ca..9fe1c516 100644 --- a/core.go +++ b/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) { diff --git a/database.go b/database.go index 70fb2133..71aa1788 100644 --- a/database.go +++ b/database.go @@ -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() { diff --git a/html/tmpl/login.html b/html/tmpl/login.html index 53b2699f..34b53be6 100644 --- a/html/tmpl/login.html +++ b/html/tmpl/login.html @@ -52,8 +52,6 @@ - - diff --git a/html/tmpl/plugins.html b/html/tmpl/plugins.html index a3c6eea7..18e944bd 100644 --- a/html/tmpl/plugins.html +++ b/html/tmpl/plugins.html @@ -22,20 +22,24 @@
...
- {{ range .Plugins }} + {{ range .Plugins }} +
-
{{safe .Form }}
+
+ {{safe .Form }} +
- {{end}} +
+ {{end}}
diff --git a/main.go b/main.go index 19002c35..e34d712c 100644 --- a/main.go +++ b/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() diff --git a/plugin/plugin.go b/plugin/plugin.go index 1f67bd90..e2c545ca 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -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() diff --git a/plugins.json b/plugins.json new file mode 100644 index 00000000..c61b1653 --- /dev/null +++ b/plugins.json @@ -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" +}] \ No newline at end of file diff --git a/plugins/slack.so b/plugins/slack.so deleted file mode 100644 index 196e479c..00000000 Binary files a/plugins/slack.so and /dev/null differ diff --git a/web.go b/web.go index d7fd3ad5..d5ae03cb 100644 --- a/web.go +++ b/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,