1
0
Fork 0
empact/server/server.go

48 lines
1.3 KiB
Go
Raw Normal View History

2015-03-05 07:46:19 +00:00
package server
import (
2015-03-18 17:29:20 +00:00
"fmt"
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"
2015-03-18 17:29:20 +00:00
"github.com/localhots/empact/config"
2015-03-07 14:56:02 +00:00
)
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-18 17:29:20 +00: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 07:46:19 +00:00
}
2015-03-06 12:15:11 +00:00
2015-03-07 14:56:02 +00:00
func dialRedis() (redis.Conn, error) {
2015-03-18 17:29:20 +00:00
return redis.Dial("tcp", fmt.Sprintf(":%d", config.C().RedisPort))
2015-03-06 12:15:11 +00:00
}