- Go 1.26.2
- Docker
Crie o arquivo de ambiente:
cp .env.example .envRevise no .env os valores de:
POSTGRES_PASSWORDLOCAL_DATABASE_URLDOCKER_DATABASE_URLAPI_KEY
Use Docker Compose pelo Makefile:
make upEsse comando faz build das imagens e sobe:
- PostgreSQL
- migrations
- API Go
- rede e volume Docker
A API ficará disponível em:
http://localhost:8080
Swagger UI:
http://localhost:8080/swagger/index.html
Valide a aplicação:
make psPara acompanhar logs:
make logsPara derrubar a stack e remover volumes:
make downAs rotas versionadas exigem uma API key:
X-API-Key: <valor de API_KEY no .env>
Também é aceito:
Authorization: Bearer <valor de API_KEY no .env>
POST /api/v1/ordersGET /api/v1/orders/{id}PATCH /api/v1/orders/{id}/statusGET /api/v1/orders
Filtros da listagem:
statuscustomerfromtopagepage_size
Criar pedido:
set -a
. ./.env
set +a
curl -X POST http://localhost:8080/api/v1/orders \
-H 'Content-Type: application/json' \
-H "X-API-Key: ${API_KEY}" \
-d '{
"customer": "customer-1",
"idempotency_key": "order-key-1",
"items": [
{
"product_id": "sku-1",
"name": "Keyboard",
"quantity": 2,
"unit_price_cents": 15000
}
]
}'Listar pedidos:
curl -H "X-API-Key: ${API_KEY}" \
'http://localhost:8080/api/v1/orders?page=1&page_size=10'- Swagger UI:
http://localhost:8080/swagger/index.html
Encontra-se no diretório: /docs