Browse Source

color code http status responses in http ui

Alan Shreve 12 years ago
parent
commit
f0a05f79ae
2 changed files with 14 additions and 1 deletions
  1. 13 0
      client/ui/http.go
  2. 1 1
      templates/page.html

+ 13 - 0
client/ui/http.go

@@ -72,6 +72,19 @@ func (h *Http) run() {
 
 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 		funcMap := template.FuncMap{
+                        "classForStatus": func(status string) string {
+                            switch status[0] {
+                                case '2':
+                                    return "text-info"
+                                case '3':
+                                    return "muted"
+                                case '4':
+                                    return "text-warning"
+                                case '5':
+                                    return "text-error"
+                            }
+                            return ""
+                        },
 			"dumpResponse": func(resp *http.Response) (interface{}, error) {
 				b, err := httputil.DumpResponse(resp, false)
 				body := new(bytes.Buffer)

+ 1 - 1
templates/page.html

@@ -89,7 +89,7 @@
                         </div>
                         <div class="span6">
                             {{ with .GetResponse }}
-                                <h3>{{ .Status }}</h3>
+                                <h3 class="{{ classForStatus .Status }}">{{ .Status }}</h3>
 
                                 {{ with $raw := dumpResponse . }}
                                     <pre><code class="http">{{ $raw }}</code></pre>