From e7a2494305310a7e1f1a4eecbad05859534ab7c3 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Fri, 6 Mar 2015 19:15:35 +0700 Subject: [PATCH] Cleanup api code using respondWith helper --- server/api.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/server/api.go b/server/api.go index f5135bc..0aee9a3 100644 --- a/server/api.go +++ b/server/api.go @@ -1,7 +1,6 @@ package server import ( - "encoding/json" "net/http" "github.com/localhots/empact/db" @@ -10,24 +9,15 @@ import ( func apiOrgsHandler(w http.ResponseWriter, r *http.Request) { login := currentUser(r) orgs := db.UserOrgs(login) - b, _ := json.Marshal(orgs) - - w.Header().Set("Content-Type", "application/json; charset=utf8") - w.Write(b) + respondWith(w, orgs) } func apiTeamsHandler(w http.ResponseWriter, r *http.Request) { teams := db.OrgTeams(r.FormValue("org")) - b, _ := json.Marshal(teams) - - w.Header().Set("Content-Type", "application/json; charset=utf8") - w.Write(b) + respondWith(w, teams) } func apiReposHandler(w http.ResponseWriter, r *http.Request) { repos := db.OrgRepos(r.FormValue("org")) - b, _ := json.Marshal(repos) - - w.Header().Set("Content-Type", "application/json; charset=utf8") - w.Write(b) + respondWith(w, repos) }