Browse Source

Code refactoring.

Wirecog 7 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
 
2
 
3
 import (
3
 import (
4
 	"net/http"
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
 	var tpl bytes.Buffer
106
 	var tpl bytes.Buffer
107
 
107
 
108
 	if err := t.Execute(&tpl, params.Data); err != nil {
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
 	div := dom.GetWindow().Document().CreateElement("div").(*dom.HTMLDivElement)
112
 	div := dom.GetWindow().Document().CreateElement("div").(*dom.HTMLDivElement)
136
 func (t *Template) RenderTemplateOnServer(params *RenderParams) {
136
 func (t *Template) RenderTemplateOnServer(params *RenderParams) {
137
 
137
 
138
 	w := params.Writer
138
 	w := params.Writer
139
-
140
 	var tpl bytes.Buffer
139
 	var tpl bytes.Buffer
141
 	if err := t.Execute(&tpl, params.Data); err != nil {
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
 	w.Write(tpl.Bytes())
143
 	w.Write(tpl.Bytes())
145
 }
144
 }