The code behind https://dns-api.org/
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
data
.gitignore
.travis.yml
Dockerfile
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
Procfile
README.md
build-all
dns.go
main.go
main_test.go
static.go
static_includes.go
static_test.go

README.md

Travis CI Go Report Card license Release gocover store

dns-api-go

This is a golang port of the old perl-based DNS-API.org site.

  • Still allows the same lookups.
  • Still has rate-limiting.

Installation

Assuming you have a working go-setup you can update & install the project via these two commands:

$ go get -u  github.com/skx/dns-api-go
$ go install github.com/skx/dns-api-go

If you don't have a golang environment configured you should be able to download a binary release from the github project.

Rate Limiting

The server has support for rate-limiting, you can enable this by passing the address of a redis server to the binary:

$ dns-api-go  -redis-server localhost:6379

If this flag is not present then rate-limiting will be disabled. If a client makes too many requests they will be returned a HTTP 429 status-code. Each request made will return a series of headers prefixed with X-RateLimit to allow clients to see how many requests they have made, and have remaining.

Metrics

If you have a graphite-host you can point the environmental-variable METRICS at it. This will then receive metrics:

  • Counts of DNS-queries by type.
  • Count of success/failure responses.
  • System-metrics.

Docker deployment

If you've cloned this repository you'll notice there is an existing Dockerfile which can be used to build a container. Create your image like so:

skx@frodo ~/go/src/github.com/skx/dns-api-go $ docker build -t dns-api:latest .
Sending build context to Docker daemon  301.1kB
Step 1/10 : FROM alpine
latest: Pulling from library/alpine
..
..
Step 10/10 : ENTRYPOINT ["/root/dns-api-go", "-host","0.0.0.0" , "-port 3001" ]
..
Successfully built

Once you have your container you can launch it like so:

 $ docker run -d -p 9999:9999/tcp dns-api:latest

And test it via:

 $ curl http://localhost:9999/txt/steve.fi

Deploying with a redis image too, to allow rate-limiting, is left as an exercise.

Heroku deployment

Get into the cloned git repository ($GOPATH/src/github.com/skx/dns-api-go) and run:

$ heroku create
$ git push heroku master

Notes

Hacking

If you alter the template-files beneath data/ you will need to rebuild the static.go file before those changes will become visible. (i.e. They are pre-processed and included inline in our generated binary, rather than being read at run-time.)

First of all install the implant tool if you don't already have it:

 $ go get -u github.com/skx/implant
 $ go install github.com/skx/implant

Now you can regenerate the static.go file:

 $ implant -input data/ -output static.go

And rebuild the main binary:

 $ go build .

Steve