mirror of https://github.com/mpolden/echoip
Rename Handlers -> Router
This commit is contained in:
parent
d560f6108a
commit
b1b3fbb5f3
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
4
main.go
4
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue