(writer http.ResponseWriter, request *http.Request)
| 14 | var htmlTemplates *template.Template |
| 15 | |
| 16 | func HandleTemplateRequest(writer http.ResponseWriter, request *http.Request) { |
| 17 | path := request.URL.Path |
| 18 | if (path == "") { |
| 19 | path = "products.html" |
| 20 | } |
| 21 | t := htmlTemplates.Lookup(path) |
| 22 | if (t == nil) { |
| 23 | http.NotFound(writer, request) |
| 24 | } else { |
| 25 | err := t.Execute(writer, Context{ request, Products}) |
| 26 | if (err != nil) { |
| 27 | http.Error(writer, err.Error(), http.StatusInternalServerError) |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func init() { |
| 33 | var err error |