Merge pull request #43 from chihaya/develop

Update to Go 1.4
This commit is contained in:
Justin Li 2015-02-03 09:22:41 -05:00
commit 54593ff5c2
7 changed files with 21 additions and 10 deletions

View file

@ -1,6 +1,6 @@
language: go language: go
go: 1.3 go: 1.4
before_install: before_install:
- go get github.com/tools/godep - go get github.com/tools/godep

12
Godeps/Godeps.json generated
View file

@ -1,12 +1,7 @@
{ {
"ImportPath": "github.com/chihaya/chihaya", "ImportPath": "github.com/chihaya/chihaya",
"GoVersion": "go1.3.3", "GoVersion": "go1.4.1",
"Deps": [ "Deps": [
{
"ImportPath": "code.google.com/p/go.net/netutil",
"Comment": "null-164",
"Rev": "6122c8c304675f19800c917359e02dd68e760a5b"
},
{ {
"ImportPath": "github.com/chihaya/bencode", "ImportPath": "github.com/chihaya/bencode",
"Rev": "1df51811f3440202aa39df93596654319ea5ff57" "Rev": "1df51811f3440202aa39df93596654319ea5ff57"
@ -34,6 +29,11 @@
{ {
"ImportPath": "github.com/stretchr/pat/stop", "ImportPath": "github.com/stretchr/pat/stop",
"Rev": "f7fe051f2b9bcaca162b38de4f93c9a8457160b9" "Rev": "f7fe051f2b9bcaca162b38de4f93c9a8457160b9"
},
{
"ImportPath": "golang.org/x/net/netutil",
"Comment": "null-204",
"Rev": "8fd8d3a0313cb59e495106ac76df5da29381fa24"
} }
] ]
} }

2
Godeps/_workspace/.gitignore generated vendored Normal file
View file

@ -0,0 +1,2 @@
/pkg
/bin

View file

@ -32,7 +32,7 @@ use-cases).
## Building & Installing ## Building & Installing
Chihaya requires Go 1.3, [Godep], and a [Go environment] previously setup. Chihaya requires Go 1.4, [Godep], and a [Go environment] previously setup.
[Godep]: https://github.com/tools/godep [Godep]: https://github.com/tools/godep
[Go environment]: https://golang.org/doc/code.html [Go environment]: https://golang.org/doc/code.html

View file

@ -19,13 +19,17 @@ import (
"github.com/chihaya/chihaya/tracker" "github.com/chihaya/chihaya/tracker"
) )
// ResponseHandler is an HTTP handler that returns a status code.
type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) (int, error) type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) (int, error)
// Server represents an HTTP serving torrent tracker.
type Server struct { type Server struct {
config *config.Config config *config.Config
tracker *tracker.Tracker tracker *tracker.Tracker
} }
// makeHandler wraps our ResponseHandlers while timing requests, collecting,
// stats, logging, and handling errors.
func makeHandler(handler ResponseHandler) httprouter.Handle { func makeHandler(handler ResponseHandler) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
var msg string var msg string
@ -63,6 +67,7 @@ func makeHandler(handler ResponseHandler) httprouter.Handle {
} }
} }
// newRouter returns a router with all the routes.
func newRouter(s *Server) *httprouter.Router { func newRouter(s *Server) *httprouter.Router {
r := httprouter.New() r := httprouter.New()
@ -91,6 +96,8 @@ func newRouter(s *Server) *httprouter.Router {
return r return r
} }
// connState is used by graceful in order to gracefully shutdown. It also
// keeps track of connection stats.
func (s *Server) connState(conn net.Conn, state http.ConnState) { func (s *Server) connState(conn net.Conn, state http.ConnState) {
switch state { switch state {
case http.StateNew: case http.StateNew:
@ -102,14 +109,16 @@ func (s *Server) connState(conn net.Conn, state http.ConnState) {
case http.StateHijacked: case http.StateHijacked:
panic("connection impossibly hijacked") panic("connection impossibly hijacked")
case http.StateActive: // Ignore. // Ignore the following cases.
case http.StateIdle: // Ignore. case http.StateActive, http.StateIdle:
default: default:
glog.Errorf("Connection transitioned to unknown state %s (%d)", state, state) glog.Errorf("Connection transitioned to unknown state %s (%d)", state, state)
} }
} }
// Serve creates a new Server and proceeds to block while handling requests
// until a graceful shutdown.
func Serve(cfg *config.Config, tkr *tracker.Tracker) { func Serve(cfg *config.Config, tkr *tracker.Tracker) {
srv := &Server{ srv := &Server{
config: cfg, config: cfg,