Repos api
This commit is contained in:
+10
-2
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/localhots/empact/db"
|
||||
)
|
||||
|
||||
func orgsListHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func apiOrgsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
login := currentUser(r)
|
||||
orgs := db.UserOrgs(login)
|
||||
b, _ := json.Marshal(orgs)
|
||||
@@ -16,10 +16,18 @@ func orgsListHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(b)
|
||||
}
|
||||
|
||||
func orgTeamsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
+3
-2
@@ -20,8 +20,9 @@ func init() {
|
||||
|
||||
http.HandleFunc("/", sessionHandler)
|
||||
http.HandleFunc("/api/", authHandler)
|
||||
http.HandleFunc("/api/orgs", orgsListHandler)
|
||||
http.HandleFunc("/api/teams", orgTeamsHandler)
|
||||
http.HandleFunc("/api/orgs", apiOrgsHandler)
|
||||
http.HandleFunc("/api/teams", apiTeamsHandler)
|
||||
http.HandleFunc("/api/repos", apiReposHandler)
|
||||
http.HandleFunc("/auth/hello", authHelloHandler)
|
||||
http.HandleFunc("/auth/signin", authSigninHandler)
|
||||
http.HandleFunc("/auth/callback", authCallbackHandler)
|
||||
|
||||
+3
-5
@@ -38,11 +38,9 @@ func sessionID(r *http.Request) string {
|
||||
return cook.Value
|
||||
}
|
||||
|
||||
func currentUser(r *http.Request) string {
|
||||
conn := redisC.Get()
|
||||
login, _ := redis.String(conn.Do("HGET", "sessions", sessionID(r)))
|
||||
|
||||
return login
|
||||
func currentUser(r *http.Request) (login string) {
|
||||
login, _ = redis.String(redisC.Get().Do("HGET", "sessions", sessionID(r)))
|
||||
return
|
||||
}
|
||||
|
||||
func authorize(r *http.Request, login string) {
|
||||
|
||||
Reference in New Issue
Block a user