1
0
Fork 0

Teams api

This commit is contained in:
Gregory Eremin 2015-03-06 17:56:46 +07:00
parent 2c4de085e7
commit 4b6f79f366
3 changed files with 11 additions and 7 deletions

View File

@ -8,10 +8,18 @@ import (
)
func orgsListHandler(w http.ResponseWriter, r *http.Request) {
jsonHandler(w, r)
login := currentUser(r)
orgs := db.UserOrgs(login)
b, _ := json.Marshal(orgs)
w.Header().Set("Content-Type", "application/json; charset=utf8")
w.Write(b)
}
func orgTeamsHandler(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)
}

View File

@ -6,7 +6,6 @@ import (
"net/url"
"github.com/localhots/empact/config"
"github.com/localhots/empact/task"
)

View File

@ -21,15 +21,12 @@ func init() {
http.HandleFunc("/", sessionHandler)
http.HandleFunc("/api/", authHandler)
http.HandleFunc("/api/orgs", orgsListHandler)
http.HandleFunc("/api/teams", orgTeamsHandler)
http.HandleFunc("/auth/hello", authHelloHandler)
http.HandleFunc("/auth/signin", authSigninHandler)
http.HandleFunc("/auth/callback", authCallbackHandler)
}
func jsonHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf8")
}
func Start() {
fmt.Println("Starting server at http://localhost:8080")
http.ListenAndServe(":8080", nil)