Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Package handlers implements HTTP handlers for the default module. | 5 // Package handlers implements HTTP handlers for the default module. |
| 6 package handlers | 6 package handlers |
| 7 | 7 |
| 8 import ( | 8 import ( |
| 9 "html/template" | 9 "html/template" |
| 10 "net/http" | 10 "net/http" |
| 11 | 11 |
| 12 "google.golang.org/appengine" | 12 "google.golang.org/appengine" |
| 13 "google.golang.org/appengine/taskqueue" | 13 "google.golang.org/appengine/taskqueue" |
| 14 ) | 14 ) |
| 15 | 15 |
| 16 func init() { | 16 func init() { |
| 17 http.HandleFunc("/", landingPageHandler) | 17 http.HandleFunc("/", landingPageHandler) |
| 18 http.HandleFunc("/analyze", analyzeHandler) | 18 http.HandleFunc("/analyze", analyzeHandler) |
| 19 } | 19 } |
| 20 | 20 |
| 21 var basePage = template.Must(template.ParseFiles("templates/base.html")) | 21 var basePage = template.Must(template.ParseFiles("templates/base.html")) |
| 22 | 22 |
| 23 func landingPageHandler(w http.ResponseWriter, r *http.Request) { | 23 func landingPageHandler(w http.ResponseWriter, r *http.Request) { |
| 24 data := map[string]interface{}{ | 24 data := map[string]interface{}{ |
| 25 "Msg": "This service is under construction ...", | 25 "Msg": "This service is under construction ...", |
| 26 "ShowRequestForm": true, | 26 "ShowRequestForm": true, |
| 27 } | 27 } |
| 28 » basePage.Execute(w, data) | 28 » if e := basePage.Execute(w, data); e != nil { |
|
nodir
2016/07/14 16:33:00
I recommend calling the variable "err" because it
emso
2016/07/15 11:04:43
Done.
| |
| 29 » » http.Error(w, e.Error(), http.StatusInternalServerError) | |
|
nodir
2016/07/14 16:33:00
the error description is sent to the user and not
emso
2016/07/15 11:04:43
Done.
| |
| 30 » » return | |
| 31 » } | |
| 29 } | 32 } |
| 30 | 33 |
| 31 func analyzeHandler(w http.ResponseWriter, r *http.Request) { | 34 func analyzeHandler(w http.ResponseWriter, r *http.Request) { |
| 32 ctx := appengine.NewContext(r) | 35 ctx := appengine.NewContext(r) |
| 33 t := taskqueue.NewPOSTTask("/workflow-launcher/queue-handler", map[strin g][]string{"name": {"Analyze Request"}}) | 36 t := taskqueue.NewPOSTTask("/workflow-launcher/queue-handler", map[strin g][]string{"name": {"Analyze Request"}}) |
| 34 if _, err := taskqueue.Add(ctx, t, "workflow-launcher-queue"); err != ni l { | 37 if _, err := taskqueue.Add(ctx, t, "workflow-launcher-queue"); err != ni l { |
| 35 http.Error(w, err.Error(), http.StatusInternalServerError) | 38 http.Error(w, err.Error(), http.StatusInternalServerError) |
| 36 return | 39 return |
| 37 } | 40 } |
| 38 data := map[string]interface{}{ | 41 data := map[string]interface{}{ |
| 39 "Msg": "Dummy analysis request sent.", | 42 "Msg": "Dummy analysis request sent.", |
| 40 } | 43 } |
| 41 » basePage.Execute(w, data) | 44 » if e := basePage.Execute(w, data); e != nil { |
| 45 » » http.Error(w, e.Error(), http.StatusInternalServerError) | |
| 46 » » return | |
| 47 » } | |
| 42 } | 48 } |
| OLD | NEW |