Updates; instable

Former-commit-id: e3f4a16286e135cb643f36fc9518a760dca82333 [formerly ffd101f980b04f10bc4bc99e43bcc3ff962993a4] [formerly 15e574f9edbd1579a12424d51aa9926e0dbd84dd [formerly ae8e97a43e]]
Former-commit-id: a2db52a130b73a1ac235630d87797edd0c38c756 [formerly bf85e68f90f75cad611b90545ce7415123de84bd]
Former-commit-id: f9915ecf27cc6c2456eb867a7d3a8beb29531e35
This commit is contained in:
Henrique Dias
2017-07-29 10:54:05 +01:00
parent 0d453229d9
commit 00be85db13
5 changed files with 212 additions and 168 deletions

25
http.go
View File

@@ -107,8 +107,8 @@ func apiHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int,
return http.StatusForbidden, nil
}
for _, p := range c.FM.Plugins {
code, err := p.BeforeAPI(c, w, r)
for p := range c.FM.Plugins {
code, err := plugins[p].Handler.Before(c, w, r)
if code != 0 || err != nil {
return code, err
}
@@ -150,8 +150,8 @@ func apiHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int,
return code, err
}
for _, p := range c.FM.Plugins {
code, err := p.AfterAPI(c, w, r)
for p := range c.FM.Plugins {
code, err := plugins[p].Handler.After(c, w, r)
if code != 0 || err != nil {
return code, err
}
@@ -194,18 +194,17 @@ func splitURL(path string) (string, string) {
// renderFile renders a file using a template with some needed variables.
func renderFile(w http.ResponseWriter, file string, contentType string, c *RequestContext) (int, error) {
functions := template.FuncMap{
"JS": func(s string) template.JS {
return template.JS(s)
},
}
tpl := template.Must(template.New("file").Funcs(functions).Parse(file))
tpl := template.Must(template.New("file").Parse(file))
w.Header().Set("Content-Type", contentType+"; charset=utf-8")
var javascript = ""
for name := range c.FM.Plugins {
javascript += plugins[name].JavaScript + "\n"
}
err := tpl.Execute(w, map[string]interface{}{
"BaseURL": c.FM.RootURL(),
"Plugins": c.FM.Plugins,
"BaseURL": c.FM.RootURL(),
"JavaScript": template.JS(javascript),
})
if err != nil {
return http.StatusInternalServerError, err