Skip to content

Commit

Permalink
#patch: cleanup redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
circa10a committed Apr 1, 2022
1 parent 3abfc89 commit b03a325
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions geofence.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,22 @@ func validateIPAddress(ipAddress string) error {

// getIPGeoData fetches geolocation data for specified IP address from https://freegeoip.app
func (g *Geofence) getIPGeoData(ipAddress string) (*FreeGeoIPResponse, error) {
freeGeoIPResponse := &FreeGeoIPResponse{}
freeGeoIPError := &FreeGeoIPError{}

resp, err := g.FreeGeoIPClient.R().
SetHeader("Accept", "application/json").
SetQueryParam("apikey", g.Token).
SetResult(&FreeGeoIPResponse{}).
SetError(&FreeGeoIPError{}).
SetResult(freeGeoIPResponse).
SetError(freeGeoIPError).
Get(ipAddress)
if err != nil {
return &FreeGeoIPResponse{}, err
return freeGeoIPResponse, err
}

// If api gives back status code >399, report error to user
if resp.IsError() {
return &FreeGeoIPResponse{}, resp.Error().(*FreeGeoIPError)
return freeGeoIPResponse, freeGeoIPError
}

return resp.Result().(*FreeGeoIPResponse), nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ require (
require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd h1:zYlwaUHTmxuf6H7hwO2dgwqozQmH7zf4x+/qql4oVWc=
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down

0 comments on commit b03a325

Please sign in to comment.