Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit cb04395

Browse files
committed
Serve results from /ip/ instead of /api/whreabouts (breaking change)
1 parent 127e26f commit cb04395

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,42 @@ Give the service a moment to download the database. Once that's done you
2424
can start sending queries to localhost port 8080:
2525

2626
```sh
27-
$ curl http://localhost:8080/api/whereabouts/8.8.8.8
27+
$ curl http://localhost:8080/ip/8.8.8.8
2828
```
2929

3030
## Command-line Options
3131

32-
* `host` The IP address or hostname that the HTTP server should listen to. Default: `localhost`.
33-
* `port` The port that the HTTP server should listen to. Default: `8080`.
34-
* `update-interval` How often database updates should be checked from `hash-url`/`update-url`. Uses Go's [Duration format](https://golang.org/pkg/time/#ParseDuration). Default: 4 hours.
35-
* `update-url` A URL for updating the database. Default: MaxMind's [GeoLite2 City](https://dev.maxmind.com/geoip/geoip2/geolite2/) database.
36-
* `hash-url` A URL pointing to a file containing an MD5 sum of the data in `update-url`. Useful for checking whether the database has updated without actually downloading the whole database. Default: Off by default, except when `update-url` points to its default value.
37-
* `init-url` A URL for the initial database load. Can be used to seed the service by e.g. baking in a snapshot of the database into the service's a Docker image. Default: The initial load will be performed from `update-url`.
32+
- `host` The IP address or hostname that the HTTP server should listen to. Default: `localhost`.
33+
- `port` The port that the HTTP server should listen to. Default: `8080`.
34+
- `update-interval` How often database updates should be checked from `hash-url`/`update-url`. Uses Go's [Duration format](https://golang.org/pkg/time/#ParseDuration). Default: 4 hours.
35+
- `update-url` A URL for updating the database. Default: MaxMind's [GeoLite2 City](https://dev.maxmind.com/geoip/geoip2/geolite2/) database.
36+
- `hash-url` A URL pointing to a file containing an MD5 sum of the data in `update-url`. Useful for checking whether the database has updated without actually downloading the whole database. Default: Off by default, except when `update-url` points to its default value.
37+
- `init-url` A URL for the initial database load. Can be used to seed the service by e.g. baking in a snapshot of the database into the service's a Docker image. Default: The initial load will be performed from `update-url`.
3838

3939
All URL options allow `http`, `https` and `file` URLs.
4040

4141
## API
4242

43-
The service supports requests to `/api/whereabouts/IP_ADDRESS` where `IP_ADDRESS`
43+
The service supports requests to `/ip/IP_ADDRESS` where `IP_ADDRESS`
4444
can be an IPv4 or IPv6 address.
4545

4646
Let's assume the service is running on localhost port 8080 and has done the
4747
initial database load. To query Google's DNS service addresses run the following:
4848

4949
```sh
50-
$ curl http://localhost:8080/api/whereabouts/8.8.8.8
50+
$ curl http://localhost:8080/ip/8.8.8.8
5151
{"continent":{"code":"NA","name":"North America"},"country":{"code":"US","name":"United States"},"city":"Mountain View"}
52-
$ curl http://localhost:8080/api/whereabouts/2001:4860:4860::8888
52+
$ curl http://localhost:8080/ip/2001:4860:4860::8888
5353
{"continent":{"code":"NA","name":"North America"},"country":{"code":"US","name":"United States"}}
54-
$ curl http://localhost:8080/api/whereabouts/192.0.2.0
54+
$ curl http://localhost:8080/ip/192.0.2.0
5555
{}
5656
```
5757

5858
If the queried IP isn't a valid IPv4/6 address the service returns status code
5959
422 (Unprocessable Entity) with a JSON formatted message object:
6060

6161
```sh
62-
$ curl http://localhost:8080/api/whereabouts/not.an.ip.address
62+
$ curl http://localhost:8080/ip/not.an.ip.address
6363
{"message": "Not an IPv4/IPv6 address"}
6464
```
6565

@@ -70,9 +70,9 @@ checks.
7070
## Baking the Database into an Image
7171

7272
The Docker image does not contain a copy of the MaxMind GeoLite2 City
73-
database, which is always loaded from MaxMind's servers when Whereabouts
73+
database, which is always loaded from MaxMind's servers when Whereabouts
7474
starts. For situations where this is not feasible (e.g. environments without
75-
external network connectivity) you can build a custom image with that uses
75+
external network connectivity) you can build a custom image with that uses
7676
baked-in data for the initial load.
7777

7878
Create a Dockerfile with `hownetworks/whereabouts` as the base image:

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func main() {
167167
}
168168
go update(md5sum[:], updateSource, hashSource)
169169

170-
http.HandleFunc("/api/whereabouts/", func(w http.ResponseWriter, r *http.Request) {
171-
path := r.URL.Path[17:]
170+
http.HandleFunc("/ip/", func(w http.ResponseWriter, r *http.Request) {
171+
path := r.URL.Path[4:]
172172
result, ok := get(path)
173173
if !ok {
174174
w.WriteHeader(http.StatusUnprocessableEntity)

0 commit comments

Comments
 (0)