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 10 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 @@
<link rel="stylesheet" type="text/css" href="<%.Cfg.S%>/css/main.min.css"> <link rel="stylesheet" type="text/css" href="<%.Cfg.S%>/css/main.min.css">
<%template "extra-head" .%> <%template "extra-head" .%>
<%.ExtraDHead%> <%.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 (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"encoding/hex" "encoding/hex"
"encoding/json"
"flag" "flag"
"fmt" "fmt"
"html/template" "html/template"
@ -208,8 +209,17 @@ func runner(runtime phoenix.Runtime) error {
} }
// Load templates. // 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 = template.New("")
templates.Delims("<%", "%>") templates.Delims("<%", "%>").Funcs(templateFuncMap)
// Load html templates folder // Load html templates folder
err = filepath.Walk(path.Join(rootFolder, "html"), func(path string, info os.FileInfo, err error) error { err = filepath.Walk(path.Join(rootFolder, "html"), func(path string, info os.FileInfo, err error) error {

Loading…
Cancel
Save