48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/garyburd/redigo/redis"
|
|
"github.com/localhots/empact/config"
|
|
)
|
|
|
|
const (
|
|
cookieName = "session_id"
|
|
)
|
|
|
|
var (
|
|
redisPool = redis.NewPool(dialRedis, 10)
|
|
)
|
|
|
|
func init() {
|
|
http.HandleFunc("/auth/signin", authSigninHandler)
|
|
http.HandleFunc("/auth/callback", authCallbackHandler)
|
|
|
|
http.HandleFunc("/api/", authHandler)
|
|
http.HandleFunc("/api/orgs", apiOrgsHandler)
|
|
http.HandleFunc("/api/teams", apiTeamsHandler)
|
|
http.HandleFunc("/api/users", apiUsersHandler)
|
|
http.HandleFunc("/api/repos", apiReposHandler)
|
|
|
|
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)
|
|
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)
|
|
}
|
|
|
|
func Start() {
|
|
log.Printf("Starting server at http://localhost:%d\n", config.C().ServerPort)
|
|
http.ListenAndServe(fmt.Sprintf(":%d", config.C().ServerPort), nil)
|
|
}
|
|
|
|
func dialRedis() (redis.Conn, error) {
|
|
return redis.Dial("tcp", fmt.Sprintf(":%d", config.C().RedisPort))
|
|
}
|