2015-03-05 14:46:19 +07:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2015-03-19 00:29:20 +07:00
|
|
|
"fmt"
|
2015-03-06 20:23:01 +07:00
|
|
|
"log"
|
2015-03-05 14:46:19 +07:00
|
|
|
"net/http"
|
2015-03-07 21:56:02 +07:00
|
|
|
|
|
|
|
"github.com/garyburd/redigo/redis"
|
2015-03-19 00:29:20 +07:00
|
|
|
"github.com/localhots/empact/config"
|
2015-03-07 21:56:02 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
cookieName = "session_id"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
redisPool = redis.NewPool(dialRedis, 10)
|
2015-03-05 20:49:50 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2015-03-06 19:36:35 +07:00
|
|
|
http.HandleFunc("/auth/signin", authSigninHandler)
|
|
|
|
http.HandleFunc("/auth/callback", authCallbackHandler)
|
2015-03-08 18:17:56 +07:00
|
|
|
|
2015-03-05 22:25:26 +07:00
|
|
|
http.HandleFunc("/api/", authHandler)
|
2015-03-06 18:18:15 +07:00
|
|
|
http.HandleFunc("/api/orgs", apiOrgsHandler)
|
|
|
|
http.HandleFunc("/api/teams", apiTeamsHandler)
|
2015-03-15 00:34:37 +07:00
|
|
|
http.HandleFunc("/api/users", apiUsersHandler)
|
2015-03-06 18:18:15 +07:00
|
|
|
http.HandleFunc("/api/repos", apiReposHandler)
|
2015-03-08 18:17:56 +07: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 21:35:25 +07: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 20:49:50 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func Start() {
|
2015-03-19 00:29:20 +07:00
|
|
|
log.Printf("Starting server at http://localhost:%d\n", config.C().ServerPort)
|
|
|
|
http.ListenAndServe(fmt.Sprintf(":%d", config.C().ServerPort), nil)
|
2015-03-05 14:46:19 +07:00
|
|
|
}
|
2015-03-06 19:15:11 +07:00
|
|
|
|
2015-03-07 21:56:02 +07:00
|
|
|
func dialRedis() (redis.Conn, error) {
|
2015-03-19 00:29:20 +07:00
|
|
|
return redis.Dial("tcp", fmt.Sprintf(":%d", config.C().RedisPort))
|
2015-03-06 19:15:11 +07:00
|
|
|
}
|