From f76048f74b4aa1da8d52f86f04742a478110f4e6 Mon Sep 17 00:00:00 2001
From: Matt Bell <mappum@gmail.com>
Date: Mon, 3 Nov 2014 20:08:08 -0800
Subject: [PATCH] commands/http: Unexported Handler fields and created
 constructor

---
 commands/http/handler.go | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/commands/http/handler.go b/commands/http/handler.go
index f23ce9a9a..8ac3e987f 100644
--- a/commands/http/handler.go
+++ b/commands/http/handler.go
@@ -9,8 +9,8 @@ import (
 )
 
 type Handler struct {
-	Ctx  cmds.Context
-	Root *cmds.Command
+	ctx  cmds.Context
+	root *cmds.Command
 }
 
 var ErrNotFound = errors.New("404 page not found")
@@ -21,8 +21,12 @@ var mimeTypes = map[string]string{
 	cmds.Text: "text/plain",
 }
 
+func NewHandler(ctx cmds.Context, root *cmds.Command) *Handler {
+	return &Handler{ctx, root}
+}
+
 func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	req, err := Parse(r, i.Root)
+	req, err := Parse(r, i.root)
 	if err != nil {
 		if err == ErrNotFound {
 			w.WriteHeader(http.StatusNotFound)
@@ -32,10 +36,10 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		w.Write([]byte(err.Error()))
 		return
 	}
-	req.SetContext(i.Ctx)
+	req.SetContext(i.ctx)
 
 	// call the command
-	res := i.Root.Call(req)
+	res := i.root.Call(req)
 
 	// set the Content-Type based on res output
 	if _, ok := res.Output().(io.Reader); ok {
-- 
GitLab