HTTP service that accepts a collection of "components"
then fans-out requests and returns aggregated content
- Components should be defined in a YAML page configuration file
- Components are requested concurrently via goroutines
- Components can be marked as "mandatory" (if they fail, the request summary is set to "failure")
components:
- id: google
url: http://google.com
- id: integralist
url: http://integralist.co.uk
mandatory: true
- id: not-found
url: http://httpstat.us/404
- id: timeout
url: http://httpstat.us/408
- id: server-error
url: http://httpstat.us/500
- id: service-unavailable
url: http://httpstat.us/503
Note: example config provided as part of this repo
{
"summary": "success",
"components": [
{
"id": "google",
"status": 200,
"body": "<!doctype html> ... </html>",
"mandatory": false
},
{
"id": "integralist",
"status": 200,
"body": "<!doctype html> ... </html>",
"mandatory": true
},
{
"id": "slooow",
"status": 408,
"body": "Get http://localhost:3000/pugs: net/http: request canceled (Client.Timeout exceeded while awaiting headers)",
"mandatory": false
}
{
"id": "not-found",
"status": 404,
"body": "404 Not Found",
"mandatory": false
}
]
}
Note: the toplevel
summary
key's value will befailure
if any mandatory components fail
docker build -t my-golang-app .
docker run --rm --name go-tester -v "$PWD":/go/src/app -p 8080:8080 my-golang-app
If you're using Docker-Machine, then executing the following command will return the results of the running application:
curl $(docker-machine ip <name_of_vm>):8080
To test what's happening inside the container then execute the following command:
docker run -it -v "$PWD":/go/src/app -p 8080:8080 my-golang-app /bin/bash
If you need to use a private repo then I've set-up the Docker container to work with them, but it does require you to pick your poison:
- Run the container interactively (
-it
) and manually enter SSH private key passphrase
OR
- Run the container interactively (
-it
) and save your SSH private key passphrase into anexpect
script
The former is safer and so it's the default option.
The latter requires you to modify the ssh.exp
file to include your passphrase and also to uncomment ssh-add /go/src/app/github_rsa
from bootstrap.sh
and put back in /ssh.exp
. But it's your responsibility to make sure you don't commit that passphrase.
Yes the latter takes a few more steps, but there was no way I was going to automate that for you and make it easy for you to shoot yourself in the foot!
Regardless of which option you choose, you'll need to modify the Docker run command slightly (to use interactive mode -it
). I'm not sure why though, if anyone has any ideas then please let me know.
So the command you need to execute, if you're pulling private repositories, is:
docker run -it -v "$HOME/.ssh/github_rsa":/go/src/app/github_rsa -v "$PWD":/go/src/app -p 8080:8080 my-golang-app
Note: I initially added both
github_rsa
andid_rsa
to the.gitignore
file and then switched to*_rsa
to try and prevent as many mistakes as possible (i.e. avoiding committing your private key to a potentially public repo); so please do be careful if your private key uses a different name!
No, I'm not specifying any private repo dependencies:
docker run --rm -v "$PWD":/go/src/app -p 8080:8080 my-golang-app
Yes, I have some dependencies coming from private repositories:
docker run -it -v "$HOME/.ssh/github_rsa":/go/src/app/github_rsa -v "$PWD":/go/src/app -p 8080:8080 my-golang-app "ssh_setup"
- run interactively (
-it
mode) - mount your ssh private key
- specify
ssh_setup
The following command only needs to be run once (it downloads the gb
tool):
go get -u github.com/constabulary/gb/...
Once you have gb
, download the dependencies (specified within the vendor/manifest
file) using:
gb vendor restore
Every time you make a change to your code, run:
gb build all && bin/requester ./src/page.yaml
Note: for other OS' and Arch's use something like
GOOS=linux GOARCH=amd64 gb build
go run src/requester/main.go src/page.yaml
curl http://localhost:8080/
(better to check via a web browser)
Note: you can also use
godo watch-server --watch
to track changes and automatically re-run
If you want to see how latency/slow responses effect the application then try also running: https://github.com/Integralist/go-slow-http-server which was specifically designed to be used alongside go-requester for testing
curl -w "@curl-format.txt" -o /dev/null -s http://localhost:8080/
Note: I've included a
curl-format.txt
file within the repo
I use http://getgb.io/ for handling dependencies. When using gb vendor fetch <pkg>
it'll place dependencies into a vendor
directory for you and thus allow gb build all
to include them within your binary. So you gain a project specific workspace without affecting your global $GOPATH
.
In order to not have a large repo (consisting of many dependency files), we .gitignore
the vendor/src
directory but we still commit the vendor/manifest
file (which acts as a dependency lockfile). This means when pulling the repo for the first time you'd need to execute gb vendor restore
.
- Refactor code so that certain aspects are loaded from other packages
- Add logic for loading page config remotely
- Dynamically change port number when run as binary
- Tests!
Copyright (c) 2015 Mark McDonnell