From 73fd32f37ed15f205c6a8b3dfc3efc1069a5909e Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Sun, 17 Apr 2016 16:03:00 +0200 Subject: [PATCH] Remove ipFromRequest field --- api/api.go | 18 +++++++----------- api/api_test.go | 7 +------ 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/api/api.go b/api/api.go index bf4ab5d..d1df5f5 100644 --- a/api/api.go +++ b/api/api.go @@ -23,10 +23,9 @@ var USER_AGENT_RE = regexp.MustCompile( ) type API struct { - Template string - IPHeader string - oracle Oracle - ipFromRequest func(string, *http.Request) (net.IP, error) + Template string + IPHeader string + oracle Oracle } type Response struct { @@ -43,10 +42,7 @@ type TestPortResponse struct { } func New(oracle Oracle) *API { - return &API{ - oracle: oracle, - ipFromRequest: ipFromRequest, - } + return &API{oracle: oracle} } func ipFromRequest(header string, r *http.Request) (net.IP, error) { @@ -66,7 +62,7 @@ func ipFromRequest(header string, r *http.Request) (net.IP, error) { } func (a *API) newResponse(r *http.Request) (Response, error) { - ip, err := a.ipFromRequest(a.IPHeader, r) + ip, err := ipFromRequest(a.IPHeader, r) if err != nil { return Response{}, err } @@ -91,7 +87,7 @@ func (a *API) newResponse(r *http.Request) (Response, error) { } func (a *API) CLIHandler(w http.ResponseWriter, r *http.Request) *appError { - ip, err := a.ipFromRequest(a.IPHeader, r) + ip, err := ipFromRequest(a.IPHeader, r) if err != nil { return internalServerError(err) } @@ -140,7 +136,7 @@ func (a *API) PortHandler(w http.ResponseWriter, r *http.Request) *appError { if port < 1 || port > 65355 { return badRequest(nil).WithMessage("Invalid port: " + vars["port"]).AsJSON() } - ip, err := a.ipFromRequest(a.IPHeader, r) + ip, err := ipFromRequest(a.IPHeader, r) if err != nil { return internalServerError(err).AsJSON() } diff --git a/api/api_test.go b/api/api_test.go index 25df69e..7687699 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -21,12 +21,7 @@ func (r *mockOracle) IsLookupCityEnabled() bool { return true } func (r *mockOracle) IsLookupPortEnabled() bool { return true } func newTestAPI() *API { - return &API{ - oracle: &mockOracle{}, - ipFromRequest: func(string, *http.Request) (net.IP, error) { - return net.ParseIP("127.0.0.1"), nil - }, - } + return &API{oracle: &mockOracle{}} } func httpGet(url string, json bool, userAgent string) (string, int, error) {