Browse Source

Added GopherJS handlers and function to fetch template bundle

Wirecog 6 years ago
parent
commit
29f162bc23
2 changed files with 52 additions and 0 deletions
  1. 38
    0
      fetchtemplatebundle.go
  2. 14
    0
      gopherjshandlers.go

+ 38
- 0
fetchtemplatebundle.go View File

@@ -0,0 +1,38 @@
1
+package isokit
2
+
3
+import (
4
+	"bytes"
5
+	"encoding/gob"
6
+
7
+	"honnef.co/go/js/xhr"
8
+)
9
+
10
+func FetchTemplateBundle(templateSetChannel chan *TemplateSet) {
11
+
12
+	data, err := xhr.Send("POST", "/template-bundle", nil)
13
+	if err != nil {
14
+		println("Encountered error: ", err)
15
+		println(err)
16
+	}
17
+	var templateBundleMap map[string]string
18
+	var templateBundleMapBuffer bytes.Buffer
19
+
20
+	dec := gob.NewDecoder(&templateBundleMapBuffer)
21
+	templateBundleMapBuffer = *bytes.NewBuffer(data)
22
+	err = dec.Decode(&templateBundleMap)
23
+
24
+	if err != nil {
25
+		println("Encountered error: ", err)
26
+		panic(err)
27
+	}
28
+
29
+	templateSet := NewTemplateSet()
30
+	err = templateSet.ImportTemplatesFromMap(templateBundleMap)
31
+
32
+	if err != nil {
33
+		println("Encountered import error: ", err)
34
+		panic(err)
35
+	}
36
+
37
+	templateSetChannel <- templateSet
38
+}

+ 14
- 0
gopherjshandlers.go View File

@@ -0,0 +1,14 @@
1
+package isokit
2
+
3
+import (
4
+	"net/http"
5
+	"os"
6
+)
7
+
8
+func GopherjsScriptHandler(w http.ResponseWriter, r *http.Request) {
9
+	http.ServeFile(w, r, os.Getenv("ISOGO_APP_ROOT")+"/client/client.js")
10
+}
11
+
12
+func GopherjsScriptMapHandler(w http.ResponseWriter, r *http.Request) {
13
+	http.ServeFile(w, r, os.Getenv("ISOGO_APP_ROOT")+"/client/client.js.map")
14
+}