Rename Handlers -> Router

This commit is contained in:
Martin Polden 2016-10-09 16:18:38 +02:00
parent d560f6108a
commit b1b3fbb5f3
3 changed files with 6 additions and 9 deletions

View File

@ -234,7 +234,7 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
func (a *API) Handlers() http.Handler {
func (a *API) Router() http.Handler {
r := mux.NewRouter()
// JSON
@ -258,8 +258,3 @@ func (a *API) Handlers() http.Handler {
return r
}
func (a *API) ListenAndServe(addr string) error {
http.Handle("/", a.Handlers())
return http.ListenAndServe(addr, nil)
}

View File

@ -48,7 +48,7 @@ func httpGet(url string, json bool, userAgent string) (string, int, error) {
func TestCLIHandlers(t *testing.T) {
log.SetOutput(ioutil.Discard)
s := httptest.NewServer(newTestAPI().Handlers())
s := httptest.NewServer(newTestAPI().Router())
var tests = []struct {
url string
@ -79,7 +79,7 @@ func TestCLIHandlers(t *testing.T) {
func TestJSONHandlers(t *testing.T) {
log.SetOutput(ioutil.Discard)
s := httptest.NewServer(newTestAPI().Handlers())
s := httptest.NewServer(newTestAPI().Router())
var tests = []struct {
url string

View File

@ -1,6 +1,8 @@
package main
import (
"net/http"
flags "github.com/jessevdk/go-flags"
"os"
@ -63,7 +65,7 @@ func main() {
api.IPHeader = opts.IPHeader
log.Printf("Listening on %s", opts.Listen)
if err := api.ListenAndServe(opts.Listen); err != nil {
if err := http.ListenAndServe(opts.Listen, api.Router()); err != nil {
log.Fatal(err)
}
}