PostgreSQL is used as the peristence layer, in order to run the application on your machine ensure you have PostgreSQL installed and running.
The application requires a .env
with the following variables.
API_PORT=8080
DB_HOST=localhost
DB_PORT=5432
DB_USER=user
DB_NAME=todos
DB_PASSWORD=password
Run the app using the command below pass thr IS_DEV
env var so that the .env
contents are loaded as expected.
IS_DEV=true go run .
podman build \
--build-arg=CGO_ENABLED=0 \
--build-arg=GOOS=linux \
--build-arg=GOARCH=amd64 \
-t go-todo:<version /> .
podman run --name=go-todo --env-file=.env -p 8080:8080 localhost/go-todo:<version />
podman run --name=go-todo \
-e API_PORT=8080 \
-e DB_HOST=localhost \
-e DB_PORT=5432 \
-e DB_USER=user \
-e DB_PASSWORD=password \
-e DB_NAME=todos \
-p 8080:8080 localhost/go-todo:v1.0.3
You should have created the targetted namespace before running the following commands.
oc new-app \
--name todo-db \
--image=registry.redhat.io/rhel8/postgresql-12:1-177 \
-e POSTGRESQL_USER=user \
-e POSTGRESQL_DATABASE=todos \
-e POSTGRESQL_PASSWORD=password
oc new-app --name todo-api --image=quay.io/cbennett/go-todo:v1.0.3 \
-e API_PORT=8080 \
-e DB_HOST=<address of postgres database /> \
-e DB_PORT=5432 \
-e DB_USER=user \
-e DB_PASSWORD=password \
-e DB_NAME=todos
podman run \
--name postgresdb \
-e POSTGRES_USER=user \
-e POSTGRES_PASSWORD=password \
-p 5432:5432 \
-v ~/dev/postgres/data \
-d postgres
Open the userr interface in your browser at http:localhost:5050
and use the credentials you have set.
podman run \
--name pgadmin \
-e 'PGADMIN_DEFAULT_EMAIL=user@example.com' \
-e 'PGADMIN_DEFAULT_PASSWORD=topsecret' \
-p 5050:80 \
-d docker.io/dpage/pgadmin4
curl http://localhost:8080/todos | jq
curl http://localhost:8080/todos/{id} | jq
curl --header "Content-Type: application/json" \
--request POST \
--data '{"task":"My todo task","author":"Colum B"}' \
http://localhost:3000/todos
curl -X PUT \
--data '{"task":"My todo task that is updated","author":"Colum B"}' \
http://localhost:8080/todos/{id} | jq
curl -X DELETE http://localhost:8080/todos/{id}