diff --git a/api/api.go b/api/api.go index b840b5c..f0a6f0f 100644 --- a/api/api.go +++ b/api/api.go @@ -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) -} diff --git a/api/api_test.go b/api/api_test.go index df048df..ddbaca4 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -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 diff --git a/main.go b/main.go index 42415da..c131c35 100644 --- a/main.go +++ b/main.go @@ -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) } }