Remove ipFromRequest field

This commit is contained in:
Martin Polden 2016-04-17 16:03:00 +02:00
parent 3134de8260
commit 73fd32f37e
2 changed files with 8 additions and 17 deletions

View File

@ -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()
}

View File

@ -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) {