upgrades - plugins

pull/10/head
Hunter Long 2018-06-10 21:08:04 -07:00
parent dfcdbcffe1
commit 4df559efc7
4 changed files with 78 additions and 12 deletions

View File

@ -6,12 +6,17 @@ import (
var (
pluginRoutes []*plugins.Routing
allPlugins []*plugins.Plugin
)
func InitPluginsDatabase() {
plugins.InitDB(db)
}
func SetAuthorized() {
}
func Routes() []*plugins.Routing {
return plugins.PluginRoutes
}

1
plugins/html/slack.html Normal file
View File

@ -0,0 +1 @@
yooyyo

View File

@ -3,24 +3,45 @@ package plugins
import (
"database/sql"
"net/http"
"fmt"
)
var (
db *sql.DB
PluginRoutes []*Routing
Plugins []*Plugin
)
type Plugin struct {
Name string
}
type Routing struct {
URL string
Method string
Handler func(http.ResponseWriter, *http.Request)
}
func Add(name string) {
plugin := &Plugin{name}
Plugins = append(Plugins, plugin)
}
func AddRoute(url string, method string, handle func(http.ResponseWriter, *http.Request)) {
route := &Routing{url, method, handle}
PluginRoutes = append(PluginRoutes, route)
}
func Authenticated(r *http.Request) bool {
return true
}
func log(msg... string) {
fmt.Println(" @plugins: ",msg)
}
func InitDB(database *sql.DB) {
db = database
}

View File

@ -1,30 +1,69 @@
package plugins
import "net/http"
import (
"net/http"
"strconv"
)
const (
SLACK_TABLE = "plugin_slack"
)
func init() {
AddRoute("save_slack", "POST", SaveIt)
AddRoute("create_slack", "GET", Create)
Add("slack")
AddRoute("install_slack", "GET", InstallSlack)
AddRoute("uninstall_slack", "GET", UninstallSlack)
AddRoute("save_slack", "POST", SaveSettings)
}
func SaveIt(w http.ResponseWriter, r *http.Request) {
type Slack struct {
Key string
Secret string
Enabled bool
Channel string
}
func InstallSlack(w http.ResponseWriter, r *http.Request) {
CreateTable()
http.Redirect(w, r, "/plugins", http.StatusSeeOther)
}
func Create(w http.ResponseWriter, r *http.Request) {
CreateTable()
func UninstallSlack(w http.ResponseWriter, r *http.Request) {
DropTable()
http.Redirect(w, r, "/plugins", http.StatusSeeOther)
}
func SaveSettings(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
key := r.PostForm.Get("key")
secret := r.PostForm.Get("secret")
enabled, _ := strconv.ParseBool(r.PostForm.Get("enabled"))
channel := r.PostForm.Get("channel")
slack := &Slack {
key,
secret,
enabled,
channel,
}
slack.UpdateTable()
http.Redirect(w, r, "/plugins", http.StatusSeeOther)
}
func CreateTable() {
sql := "CREATE TABLE slack (enabled BOOLEAN, api_key text, api_key text, channel text);"
sql := "CREATE TABLE "+SLACK_TABLE+" (enabled BOOLEAN, api_key text, api_secret text, channel text);"
db.QueryRow(sql).Scan()
}
func (s *Slack) UpdateTable() {
sql := "CREATE TABLE "+SLACK_TABLE+" (enabled BOOLEAN, api_key text, api_key text, channel text);"
db.QueryRow(sql).Scan()
}
func DropTable() {
sql := "DROP TABLE slack;"
sql := "DROP TABLE "+SLACK_TABLE+";"
db.QueryRow(sql).Scan()
}
func UpdateDatabase() {
}