2015-03-05 07:46:19 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2015-03-06 13:23:01 +00:00
|
|
|
"log"
|
2015-03-05 07:46:19 +00:00
|
|
|
"net/http"
|
2015-03-07 14:56:02 +00:00
|
|
|
|
|
|
|
"github.com/garyburd/redigo/redis"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
cookieName = "session_id"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
redisPool = redis.NewPool(dialRedis, 10)
|
2015-03-05 13:49:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2015-03-06 12:36:35 +00:00
|
|
|
http.HandleFunc("/auth/signin", authSigninHandler)
|
|
|
|
http.HandleFunc("/auth/callback", authCallbackHandler)
|
2015-03-08 11:17:56 +00:00
|
|
|
|
2015-03-05 15:25:26 +00:00
|
|
|
http.HandleFunc("/api/", authHandler)
|
2015-03-06 11:18:15 +00:00
|
|
|
http.HandleFunc("/api/orgs", apiOrgsHandler)
|
|
|
|
http.HandleFunc("/api/teams", apiTeamsHandler)
|
2015-03-14 17:34:37 +00:00
|
|
|
http.HandleFunc("/api/users", apiUsersHandler)
|
2015-03-06 11:18:15 +00:00
|
|
|
http.HandleFunc("/api/repos", apiReposHandler)
|
2015-03-08 11:17:56 +00:00
|
|
|
|
|
|
|
http.HandleFunc("/api/stat/orgs/top", statOrgTopHandler)
|
|
|
|
http.HandleFunc("/api/stat/orgs/activity", statOrgActivityHandler)
|
|
|
|
http.HandleFunc("/api/stat/teams/top", statTeamTopHandler)
|
|
|
|
http.HandleFunc("/api/stat/teams/activity", statTeamActivityHandler)
|
2015-03-08 14:35:25 +00:00
|
|
|
http.HandleFunc("/api/stat/users/top", statUserTopHandler)
|
|
|
|
http.HandleFunc("/api/stat/users/activity", statUserActivityHandler)
|
|
|
|
http.HandleFunc("/api/stat/repos/top", statRepoTopHandler)
|
|
|
|
http.HandleFunc("/api/stat/repos/activity", statRepoActivityHandler)
|
2015-03-05 13:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Start() {
|
2015-03-06 13:23:01 +00:00
|
|
|
log.Println("Starting server at http://localhost:8080")
|
2015-03-05 07:46:19 +00:00
|
|
|
http.ListenAndServe(":8080", nil)
|
|
|
|
}
|
2015-03-06 12:15:11 +00:00
|
|
|
|
2015-03-07 14:56:02 +00:00
|
|
|
func dialRedis() (redis.Conn, error) {
|
|
|
|
return redis.Dial("tcp", ":6379")
|
2015-03-06 12:15:11 +00:00
|
|
|
}
|