From df5ad919f9e8f2f289edb6ea8db644e5423d2794 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Wed, 16 Jul 2014 11:52:25 -0400 Subject: [PATCH] Use a constant for the JSON Content-Type --- http/api.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/http/api.go b/http/api.go index 872de88..331e173 100644 --- a/http/api.go +++ b/http/api.go @@ -16,6 +16,8 @@ import ( "github.com/chihaya/chihaya/models" ) +const jsonContentType = "application/json; charset=UTF-8" + func (t *Tracker) check(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) { _, err := w.Write([]byte("An easter egg goes here.")) if err != nil { @@ -43,7 +45,7 @@ func (t *Tracker) getTorrent(w http.ResponseWriter, r *http.Request, p httproute return http.StatusInternalServerError, err } - w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.Header().Set("Content-Type", jsonContentType) e := json.NewEncoder(w) err = e.Encode(torrent) if err != nil { @@ -112,7 +114,7 @@ func (t *Tracker) getUser(w http.ResponseWriter, r *http.Request, p httprouter.P return http.StatusInternalServerError, err } - w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.Header().Set("Content-Type", jsonContentType) e := json.NewEncoder(w) err = e.Encode(user) if err != nil {