News CRUD microservice written in Golang
Requirements for the task:
- Write a Golang microservice for CRUD operations with news.
-
POST /posts
-
GET /posts
-
PUT /posts/{id}
-
GET /posts/{id}
-
DELETE /posts/{id}
-
Post minimum contains: id, title, content, created_at, updated_at.
-
Tests are required. (using testcontainers-go for spinning postgres docker containers)
- Use PostgreSQL
- Makefile
- Data validation (using reflection)
- Migration (using Goose)
- OpenAPI specification (using go-swagger)
- REST microservice
Upload the code to Github.
There should be startup instructions. Ideally, this is a Makefile for assembly and a docker-compose file that should raise the DB instance
The following will be assessed:
- Organization of the API
- Tests (successful and failed cases)
- Postgres for DB
- Docker compose for local development
- Air for hot reload
- You should create .env.local in root folder and paste these secrets:
DB_USER=postgres
DB_PASSWORD=admin
DB_NAME=news
DB_PORT=5432
DB_HOST=db #changed during deployment, from docker-compose if local development
POSTGRES_USER=postgres
POSTGRES_PASSWORD=admin
POSTGRES_DB=news
- Run make docker-up to start api and db locally
- Apply Goose migration:
- Install Goose locally
- Run migration with your connection string (instructions here)
export GOOSE_DRIVER=postgres
export GOOSE_DBSTRING=postgresql://postgres:admin@127.0.0.1:5432/news?sslmode=disable
make migrate-up
- Once you have up and running both your containers: You can start making requests to app on port 3000. See postman collection attached in /postman folder.
- Swagger OPENAPI specification is available at GET http://localhost:3000/swagger