upgrades - plugins

pull/10/head
Hunter Long 2018-06-11 02:58:41 -07:00
parent 9a510c8dfc
commit c7ff4ef9ef
7 changed files with 49 additions and 46 deletions

View File

@ -11,7 +11,7 @@ type Core struct {
Key string Key string
Secret string Secret string
Version string Version string
Plugins []*plugin.Plugin Plugins []*plugin.PluginInfo
} }
func SelectCore() (*Core, error) { func SelectCore() (*Core, error) {

View File

@ -18,27 +18,25 @@
<div class="row"> <div class="row">
{{ range .Plugins }}
{{ . }}
{{end}}
<div class="col-4"> <div class="col-4">
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical"> <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> <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>
<a class="nav-link" id="v-pills-profile-tab" data-toggle="pill" href="#v-pills-profile" role="tab" aria-controls="v-pills-profile" aria-selected="false">Slack Integration</a> {{ range .Plugins }}
<a class="nav-link" id="v-pills-messages-tab" data-toggle="pill" href="#v-pills-messages" role="tab" aria-controls="v-pills-messages" aria-selected="false">Email</a> <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>
<a class="nav-link" id="v-pills-settings-tab" data-toggle="pill" href="#v-pills-settings" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</a> {{end}}
</div> </div>
</div> </div>
<div class="col-8"> <div class="col-8">
<div class="tab-content" id="v-pills-tabContent"> <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> <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" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">{{template "slack"}}</div>
<div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">...</div> {{ range .Plugins }}
<div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">...</div>
<div class="tab-pane fade" id="v-pills-{{.Name}}" role="tabpanel" aria-labelledby="v-pills-{{.Name}}-tab">{{safe .Form }}</div>
{{end}}
</div> </div>
</div> </div>

View File

@ -25,7 +25,6 @@
<label for="inputState">Database Connection</label> <label for="inputState">Database Connection</label>
<select id="inputState" name="db_connection" class="form-control"> <select id="inputState" name="db_connection" class="form-control">
<option selected value="postgres">Postgres</option> <option selected value="postgres">Postgres</option>
<option value="mysql">MySQL</option>
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">

40
main.go
View File

@ -25,7 +25,7 @@ var (
jsBox *rice.Box jsBox *rice.Box
tmplBox *rice.Box tmplBox *rice.Box
setupMode bool setupMode bool
allPlugins []*plugin.Plugin allPlugins []*plugin.PluginInfo
) )
type Config struct { type Config struct {
@ -40,6 +40,7 @@ type Config struct {
func main() { func main() {
VERSION = "1.1.1" VERSION = "1.1.1"
fmt.Printf("Starting Statup v%v\n", VERSION)
RenderBoxes() RenderBoxes()
configs = LoadConfig() configs = LoadConfig()
if configs == nil { if configs == nil {
@ -51,11 +52,6 @@ func main() {
} }
type Greeter interface {
Greet()
}
func mainProcess() { func mainProcess() {
var err error var err error
DbConnection() DbConnection()
@ -71,52 +67,54 @@ func mainProcess() {
} }
func ForEachPlugin() {
if len(core.Plugins) > 0 {
//for _, p := range core.Plugins {
// p.OnShutdown()
//}
}
}
func LoadPlugins() { func LoadPlugins() {
ForEachPlugin()
files, err := ioutil.ReadDir("./plugins") files, err := ioutil.ReadDir("./plugins")
if err != nil { if err != nil {
fmt.Printf("Plugins directory was not found. Error: %v\n", err) fmt.Printf("Plugins directory was not found. Error: %v\n", err)
return return
} }
for _, f := range files { for _, f := range files {
ext := strings.Split(f.Name(), ".") ext := strings.Split(f.Name(), ".")
if len(ext) != 2 { if len(ext) != 2 {
continue continue
} }
if ext[1] == "so" { if ext[1] == "so" {
plug, err := plg.Open("plugins/"+f.Name()) plug, err := plg.Open("plugins/"+f.Name())
if err != nil { if err != nil {
fmt.Printf("Plugin '%v' could not load correctly.\n", f.Name()) fmt.Printf("Plugin '%v' could not load correctly.\n", f.Name())
continue continue
} }
symPlugin, err := plug.Lookup("Plugin") symPlugin, err := plug.Lookup("Plugin")
var plugActions plugin.PluginActions var plugActions plugin.PluginActions
plugActions, ok := symPlugin.(plugin.PluginActions) plugActions, ok := symPlugin.(plugin.PluginActions)
if !ok { if !ok {
fmt.Printf("Plugin '%v' could not load correctly, error: %v\n", f.Name(), "unexpected type from module symbol") fmt.Printf("Plugin '%v' could not load correctly, error: %v\n", f.Name(), "unexpected type from module symbol")
continue continue
} }
plugin := plugActions.Plugin() //plugin := plugActions.Plugin()
//
//fmt.Println(plugin.OnLoad)
fmt.Printf("Plugin Loaded '%v' created by: %v\n", plugin.Name, plugin.Creator)
plugActions.OnLoad() plugActions.OnLoad()
fmt.Println(plugActions.Form()) allPlugins = append(allPlugins, plugActions.Plugin())
allPlugins = append(allPlugins, plugin)
} }
} }
core.Plugins = allPlugins core.Plugins = allPlugins
fmt.Printf("Loaded %v Plugins\n", len(allPlugins)) fmt.Printf("Loaded %v Plugins\n", len(allPlugins))
ForEachPlugin()
} }
func RenderBoxes() { func RenderBoxes() {

View File

@ -9,12 +9,13 @@ var (
DB *sql.DB DB *sql.DB
) )
type Plugin struct { type PluginInfo struct {
PluginActions PluginActions
Name string Name string
Creator string Creator string
Version string Version string
InstallSQL string InstallSQL string
Form string
Routes []*Routing Routes []*Routing
} }
@ -25,22 +26,23 @@ type Routing struct {
} }
type PluginActions interface { type PluginActions interface {
Plugin() *Plugin Plugin() *PluginInfo
OnLoad() SaveForm()
Install() OnInstall()
Uninstall() OnUninstall()
Save()
Form() string
OnNewUser()
OnFailure() OnFailure()
OnHit() OnHit()
OnSettingsSaved()
OnNewUser()
OnShutdown()
OnLoad()
} }
func SetDatabase(db *sql.DB) { func SetDatabase(db *sql.DB) {
DB = db DB = db
} }
func (p *Plugin) InstallPlugin(w http.ResponseWriter, r *http.Request) { func (p *PluginInfo) InstallPlugin(w http.ResponseWriter, r *http.Request) {
//sql := "CREATE TABLE " + p.Name + " (enabled BOOLEAN, api_key text, api_secret text, channel text);" //sql := "CREATE TABLE " + p.Name + " (enabled BOOLEAN, api_key text, api_secret text, channel text);"
//db.QueryRow(p.InstallSQL()).Scan() //db.QueryRow(p.InstallSQL()).Scan()
@ -48,11 +50,11 @@ func (p *Plugin) InstallPlugin(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/plugins", http.StatusSeeOther) http.Redirect(w, r, "/plugins", http.StatusSeeOther)
} }
func (p *Plugin) UninstallPlugin(w http.ResponseWriter, r *http.Request) { func (p *PluginInfo) UninstallPlugin(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/plugins", http.StatusSeeOther) http.Redirect(w, r, "/plugins", http.StatusSeeOther)
} }
func (p *Plugin) SavePlugin(w http.ResponseWriter, r *http.Request) { func (p *PluginInfo) SavePlugin(w http.ResponseWriter, r *http.Request) {
//values := r.PostForm //values := r.PostForm
//p.SaveFunc(values) //p.SaveFunc(values)
http.Redirect(w, r, "/plugins", http.StatusSeeOther) http.Redirect(w, r, "/plugins", http.StatusSeeOther)

Binary file not shown.

6
web.go
View File

@ -280,6 +280,9 @@ func Parse(file string) *template.Template {
"js": func(html string) template.JS { "js": func(html string) template.JS {
return template.JS(html) return template.JS(html)
}, },
"safe": func(html string) template.HTML {
return template.HTML(html)
},
}) })
t, _ = t.Parse(nav) t, _ = t.Parse(nav)
t.Parse(render) t.Parse(render)
@ -298,6 +301,9 @@ func ParsePlugins(file string) *template.Template {
"js": func(html string) template.JS { "js": func(html string) template.JS {
return template.JS(html) return template.JS(html)
}, },
"safe": func(html string) template.HTML {
return template.HTML(html)
},
}) })
t, _ = t.Parse(nav) t, _ = t.Parse(nav)
t.Parse(slack) t.Parse(slack)