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
Secret string
Version string
Plugins []*plugin.Plugin
Plugins []*plugin.PluginInfo
}
func SelectCore() (*Core, error) {

View File

@ -18,27 +18,25 @@
<div class="row">
{{ range .Plugins }}
{{ . }}
{{end}}
<div class="col-4">
<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" 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>
<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" id="v-pills-settings-tab" data-toggle="pill" href="#v-pills-settings" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</a>
{{ 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}}
</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>
<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>
<div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">...</div>
{{ range .Plugins }}
<div class="tab-pane fade" id="v-pills-{{.Name}}" role="tabpanel" aria-labelledby="v-pills-{{.Name}}-tab">{{safe .Form }}</div>
{{end}}
</div>
</div>

View File

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

40
main.go
View File

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

View File

@ -9,12 +9,13 @@ var (
DB *sql.DB
)
type Plugin struct {
type PluginInfo struct {
PluginActions
Name string
Creator string
Version string
InstallSQL string
Form string
Routes []*Routing
}
@ -25,22 +26,23 @@ type Routing struct {
}
type PluginActions interface {
Plugin() *Plugin
OnLoad()
Install()
Uninstall()
Save()
Form() string
OnNewUser()
Plugin() *PluginInfo
SaveForm()
OnInstall()
OnUninstall()
OnFailure()
OnHit()
OnSettingsSaved()
OnNewUser()
OnShutdown()
OnLoad()
}
func SetDatabase(db *sql.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);"
//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)
}
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)
}
func (p *Plugin) SavePlugin(w http.ResponseWriter, r *http.Request) {
func (p *PluginInfo) SavePlugin(w http.ResponseWriter, r *http.Request) {
//values := r.PostForm
//p.SaveFunc(values)
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 {
return template.JS(html)
},
"safe": func(html string) template.HTML {
return template.HTML(html)
},
})
t, _ = t.Parse(nav)
t.Parse(render)
@ -298,6 +301,9 @@ func ParsePlugins(file string) *template.Template {
"js": func(html string) template.JS {
return template.JS(html)
},
"safe": func(html string) template.HTML {
return template.HTML(html)
},
})
t, _ = t.Parse(nav)
t.Parse(slack)