12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package isokit
-
- import (
- "bytes"
- "encoding/gob"
- "html/template"
-
- "honnef.co/go/js/xhr"
- )
-
- func FetchTemplateBundle(templateSetChannel chan *TemplateSet) {
-
- data, err := xhr.Send("POST", "/template-bundle", nil)
- if err != nil {
- println("Encountered error: ", err)
- println(err)
- }
- var templateBundleMap map[string]string
- var templateBundleMapBuffer bytes.Buffer
-
- dec := gob.NewDecoder(&templateBundleMapBuffer)
- templateBundleMapBuffer = *bytes.NewBuffer(data)
- err = dec.Decode(&templateBundleMap)
-
- if err != nil {
- println("Encountered error: ", err)
- panic(err)
- }
-
- templateSet := NewTemplateSet()
- err = templateSet.ImportTemplatesFromMap(templateBundleMap)
-
- if err != nil {
- println("Encountered import error: ", err)
- panic(err)
- }
-
- templateSetChannel <- templateSet
- }
-
- func FetchTemplateBundleWithSuppliedFunctionMap(templateSetChannel chan *TemplateSet, funcMap template.FuncMap) {
-
- data, err := xhr.Send("POST", "/template-bundle", nil)
- if err != nil {
- println("Encountered error: ", err)
- println(err)
- }
- var templateBundleMap map[string]string
- var templateBundleMapBuffer bytes.Buffer
-
- dec := gob.NewDecoder(&templateBundleMapBuffer)
- templateBundleMapBuffer = *bytes.NewBuffer(data)
- err = dec.Decode(&templateBundleMap)
-
- if err != nil {
- println("Encountered error: ", err)
- panic(err)
- }
-
- templateSet := NewTemplateSet()
- templateSet.Funcs = funcMap
- err = templateSet.ImportTemplatesFromMap(templateBundleMap)
-
- if err != nil {
- println("Encountered import error: ", err)
- panic(err)
- }
-
- templateSetChannel <- templateSet
- }
|