Cleanup api code using respondWith helper
This commit is contained in:
parent
3f034017f2
commit
e7a2494305
server
|
@ -1,7 +1,6 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/localhots/empact/db"
|
"github.com/localhots/empact/db"
|
||||||
|
@ -10,24 +9,15 @@ import (
|
||||||
func apiOrgsHandler(w http.ResponseWriter, r *http.Request) {
|
func apiOrgsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
login := currentUser(r)
|
login := currentUser(r)
|
||||||
orgs := db.UserOrgs(login)
|
orgs := db.UserOrgs(login)
|
||||||
b, _ := json.Marshal(orgs)
|
respondWith(w, orgs)
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf8")
|
|
||||||
w.Write(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiTeamsHandler(w http.ResponseWriter, r *http.Request) {
|
func apiTeamsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
teams := db.OrgTeams(r.FormValue("org"))
|
teams := db.OrgTeams(r.FormValue("org"))
|
||||||
b, _ := json.Marshal(teams)
|
respondWith(w, teams)
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf8")
|
|
||||||
w.Write(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiReposHandler(w http.ResponseWriter, r *http.Request) {
|
func apiReposHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
repos := db.OrgRepos(r.FormValue("org"))
|
repos := db.OrgRepos(r.FormValue("org"))
|
||||||
b, _ := json.Marshal(repos)
|
respondWith(w, repos)
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf8")
|
|
||||||
w.Write(b)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue