iciantoine / todo-go-api

Simple Todo list Go server. Uses Go and PostgreSQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TODO Go API

Simple Todo list Go server. Uses Go and PostgreSQL

API documentation

See openapi.yaml.

Local setup

Golang linters

Install golangci-lint:

brew install golangci-lint

PostgreSQL

You will need psql binary. On MacOS install it via homebrew:

brew install libpq

Development

Local build

# install build and development dependencies
make prepare
# build app
make

Local run

The following command will create and run detached Docker containers running a PostgreSQL database with an Adminer instance

# start containers
docker compose up -d
# setup database
make reset-db
# start server
make run-server
# shutdown
docker compose down

Database

Initial setup

When the local PostgreSQL database is empty or brand new, run the following script to create the schema:

docker-compose up -d
make reset-db

Create a new migration

tern -m database/iban/migrations new <name>

Migrate to latest version

make migrate-up

Testing database migrations locally

# migrate one version up
tern migrate -c database/migrations/tern.conf -m database/migrations -d +1

# migrate one version down
tern migrate -c database/migrations/tern.conf -m database/migrations -d -1

# migrate one version up again
tern migrate -c database/migrations/tern.conf -m database/migrations -d +1

If no error occurred, then the migration is fine.

Testing

Unit tests

No setup required.

make unit

Integration tests

Requires a full local setup.

docker-compose up -d
make integration

About

Simple Todo list Go server. Uses Go and PostgreSQL


Languages

Language:Go 95.1%Language:Makefile 4.0%Language:Dockerfile 0.9%