This project implements a service to query Brazilian address information based on CEP (postal code) using the ViaCEP API. It's structured following Clean Architecture principles.
/cmd
: Main application entry point./domain
: Core domain entities (e.g.,Address
)./usecase
: Application-specific business logic (services)./interfaces
: Adapters to external systems./interfaces/services
: Clients for external services (e.g., ViaCEP client)./interfaces/http
: HTTP handlers for exposing the API.
- Go (version 1.16 or higher)
- Clone the repository.
- Navigate to the project directory.
- Build the application:
go build -o cep-service ./cmd/main.go
- Run the application:
The server will start on port 8080.
./cep-service
- URL:
/cep/{cep_value}
- Method:
GET
- Description: Retrieves address information for the given CEP.
- Example:
GET /cep/01001000
- Success Response (200 OK):
{ "cep": "01001-000", "logradouro": "Praça da Sé", "complemento": "lado ímpar", "bairro": "Sé", "localidade": "São Paulo", "uf": "SP", "ibge": "3550308", "gia": "1004", "ddd": "11", "siafi": "7107" }
- Error Responses:
400 Bad Request
: If the CEP is missing or invalid in the request.{ "error": "CEP must be provided in the URL path, e.g., /cep/01001000" }
404 Not Found
: If the CEP is not found.{ "error": "Address not found for CEP: <cep_value>" }
500 Internal Server Error
: For other server-side errors.{ "error": "Internal server error" }
Navigate to the project directory and run:
go test ./...
This will execute all tests in the project.