Skip to content

Repo for basic GO Todo app using Chi and Postgres

Notifications You must be signed in to change notification settings

col1985/go-todo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Todo App

Prerequites

Storage

PostgreSQL is used as the peristence layer, in order to run the application on your machine ensure you have PostgreSQL installed and running.

Environment Variables

The application requires a .env with the following variables.

API_PORT=8080

DB_HOST=
DB_PORT=
DB_USER=
DB_NAME=
DB_PASSWORD=

Development with Podman

Building the app using a Containerfile

podman build \
--build-arg=CGO_ENABLED=0 \
--build-arg=GOOS=linux \
--build-arg=GOARCH=amd64 \
-t go-todo:<version /> .

Running the app using Podman

podman run --name=go-todo --env-file=.env -p 8080:8080 localhost/go-todo:<version />
podman run --name=go-todo \
--pod=go-todo-pod \
-e API_PORT=8080 \
-e DB_HOST=localhost \
-e DB_PORT=5432 \
-e DB_USER=username \
-e DB_PASSWORD=password \
-e DB_NAME=tasks \
-p 8080:8080 localhost/go-todo:<version />
oc new-app --name todo-api --image=quay.io/cbennett/go-todo:v1.0.3 \
-e API_PORT=8080 \
-e DB_HOST= \
-e DB_PORT=5432 \
-e DB_USER=user \
-e DB_PASSWORD=password \
-e DB_NAME=tasks

Running Postgres PGAdmin with Podman

oc new-app \
  --name todo-db-postgresql \
  --image=registry.redhat.io/rhel8/postgresql-12:1-177 \
  -e POSTGRESQL_USER=user \
  -e POSTGRESQL_DATABASE=db \
  -e POSTGRESQL_PASSWORD=password
podman run \
--pod=go-todo-pod \
--name postgresdb \
-e POSTGRES_USER=username \
-e POSTGRES_PASSWORD=password \
-p 5432:5432 \
-v ~/dev/postgres/data \
-d postgres
podman run --pod=go-todo-pod \
--name=go-todo \
--env-file=.env localhost/go-todo:v1.0.0
podman run --pod=go-todo-pod \
--name postgresdb \
-e POSTGRES_USER=username \
-e POSTGRES_PASSWORD=password \
-v ~/dev/postgres/data \
-d postgres
podman run --pod=go-todo-pod \
-e 'PGADMIN_DEFAULT_EMAIL=user@example.com' \
-e 'PGADMIN_DEFAULT_PASSWORD=topsecret' \
--name pgadmin \
-d docker.io/dpage/pgadmin4

Testing the API

Get List

curl http://localhost:8080/todos | jq

Get Todo using ID

curl http://localhost:8080/todos/{id} | jq

Create Todo

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"task":"My todo task","author":"Colum B"}' \
  http://localhost:3000/todos

Update Todo

curl -X PUT \
  --data '{"task":"My todo task that is updated","author":"Colum B"}' \
  http://localhost:8080/todos/{id} | jq

Delete Todo

curl -X DELETE http://localhost:8080/todos/{id}

About

Repo for basic GO Todo app using Chi and Postgres

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published