A simple REST API made using net/http and sqlite3.
Build the project from the root folder.
go build -o blue-gopher ./cmd/api
./blue-gopherThe project uses Layered Architecture with a clear responsability separation and business logic isolation.
├── cmd
│ ├── api
│ └── mailworker
├── docs
├── internal
│ ├── customerrors
│ ├── database
│ │ └── migrations
│ ├── domain
│ ├── http
│ │ ├── handlers
│ │ └── routers
│ ├── messaging
│ │ ├── events
│ │ └── rabbitmq
│ ├── middleware
│ ├── repositories
│ └── services
├── pkg
│ └── config
└── test
Application entrypoint. It contains:
main.go- Server initialization
- Dependency setup
- Manual Dependency Injection
- RabbitMQ workers
Private Application code (can't be imported by other modules).
Contains business entities and core domain models. This layer does not depends on HTTP or database implementations.
Responsible for data access. It is responsible for interaction with SQL or an ORM with each table.
Contains business logic. It is responsible for:
- Validations
- Business rules
- Orchestrating repository calls
Transport layer
- Receive HTTP requests
- Decode and validate input
- Call services
- Return JSON responses
- Route registration
- Mapping endpoint to handlers
- Middleware calls
RabbitMQ middleware and events
HTTP middleware such as:
- Logging
- Authentication
- CORS
Handles:
- Database initialization
- Database connection setup
- Migration execution
Versioned .sql files.
Application specific errors.
Reusable configuration layer. Handles:
- Environment variables
- Configuration structs
Contains:
- Unit tests
HTTP Request
↓
Router
↓
Middleware
↓
Handler
↓
Service
↓
Repository
↓
Database