Browse Source

Code refactoring.

Wirecog, LLC 3 years ago
parent
commit
1f02d6d25d
2 changed files with 10 additions and 8 deletions
  1. 8
    5
      gopherjshandlers.go
  2. 2
    3
      template.go

+ 8
- 5
gopherjshandlers.go View File

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

+ 2
- 3
template.go View File

@@ -106,7 +106,7 @@ func (t *Template) RenderTemplateOnClient(params *RenderParams) {
106 106
 	var tpl bytes.Buffer
107 107
 
108 108
 	if err := t.Execute(&tpl, params.Data); err != nil {
109
-		println("error: ", err)
109
+		println("Error encountered when attempting to render template on client: ", err)
110 110
 	}
111 111
 
112 112
 	div := dom.GetWindow().Document().CreateElement("div").(*dom.HTMLDivElement)
@@ -136,10 +136,9 @@ func (t *Template) RenderTemplateOnClient(params *RenderParams) {
136 136
 func (t *Template) RenderTemplateOnServer(params *RenderParams) {
137 137
 
138 138
 	w := params.Writer
139
-
140 139
 	var tpl bytes.Buffer
141 140
 	if err := t.Execute(&tpl, params.Data); err != nil {
142
-		println("error: ", err)
141
+		println("Error encountered when attempting to render template on server: ", err)
143 142
 	}
144 143
 	w.Write(tpl.Bytes())
145 144
 }