This section contains the list of prerequisites as well as installation information for each.
- Go version 1.14. To install download the latest Go 1.14 package for your machine's OS at https://golang.org/dl/. Then follow the steps for your OS and installation method at https://golang.org/doc/install to unpackage the binary and make executable on your machine.
- Docker version 19.03. Follow the instructions at https://docs.docker.com/get-docker/ to install docker for your machine's OS.
Using the provided Dockerfile to build image hello-world:latest, run the command in the project root directory:
docker build . -t hello-world
Run the API container with docker run. The API listens on port 8080 in the container. To access the endpoints you need to specify a port on your host machine to forward to port 8080 on the container by adding -p <HOST PORT>:8080 to the docker run command. From here on out, the instructions assume port 8080 is also being used on the host machine.
docker run -itd -p 8080:8080 --name hello-world-api hello-world
Debug logs will look like the following 2020/07/13 01:50:43 - localhost:8080/.
Debug logging can be enabled upon container startup. To enable logging use the following command:
docker run -itd -p 8080:8080 --name hello-world-api hello-world api --debug
To access the logs run:
docker logs hello-world-api
Here are some example curls to test and their expected results:
curl localhost:8080/returns<p>Hello, World</p>curl -H 'Accept: application/json' localhost:8080/returns{"message": "Hello, World"}curl -H 'Accept: image/webp' localhost:8080/returns<p>Hello, World</p>curl -X POST localhost:8080/returns<p>Hello, World</p>
To run the go API tests in web/web_test.go the options are to call:
go test -v ./...from the project root directorygo test -v ./webfrom the project root directorygo test -vfrom theweb/directory
To tear down API container execute command:
docker stop hello-world-api && docker rm hello-world-api