Browse Source

Fix Go 1.8 compatibility

Go has apparently modified their template system. Objects in
templates are no longer JSON-encoded by default.
pull/398/head
Leon Klingele 9 years ago
parent
commit
38fa8bf961
No known key found for this signature in database
GPG Key ID: 83AEC0FEBAA5D483
  1. 2
      html/head.html
  2. 12
      src/app/spreed-webrtc-server/main.go

2
html/head.html

@ -12,4 +12,4 @@ @@ -12,4 +12,4 @@
<link rel="stylesheet" type="text/css" href="<%.Cfg.S%>/css/main.min.css">
<%template "extra-head" .%>
<%.ExtraDHead%>
<script id="globalcontext" type="application/json"><%$%></script><%end%>
<script id="globalcontext" type="application/json"><%json .%></script><%end%>

12
src/app/spreed-webrtc-server/main.go

@ -25,6 +25,7 @@ import ( @@ -25,6 +25,7 @@ import (
"bytes"
"crypto/rand"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"html/template"
@ -208,8 +209,17 @@ func runner(runtime phoenix.Runtime) error { @@ -208,8 +209,17 @@ func runner(runtime phoenix.Runtime) error {
}
// Load templates.
templateFuncMap := template.FuncMap{
"json": func(obj interface{}) (template.HTML, error) {
data, err := json.Marshal(obj)
if err != nil {
return "", err
}
return template.HTML(data), nil
},
}
templates = template.New("")
templates.Delims("<%", "%>")
templates.Delims("<%", "%>").Funcs(templateFuncMap)
// Load html templates folder
err = filepath.Walk(path.Join(rootFolder, "html"), func(path string, info os.FileInfo, err error) error {

Loading…
Cancel
Save