|
@@ -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
|
+}
|