This project is an example of a RESTful CRUD service implemented in Go, inspired by Clean Architecture principles.
The service allows you to create, retrieve, update, and delete records about people (Person) in a PostgreSQL database.
- Language: Go
- HTTP Framework: Echo
- Database Access: gocraft/dbr
- Logging: logrus
- Validation: go-playground/validator
- Database: PostgreSQL
The project is divided into 4 layers:
- internal/app — model definition (Person)
- internal/http — HTTP handlers
- internal/logic — business logic (use cases)
- internal/repository/postgres — data access layer (PostgreSQL)
type Person struct {
ID int64 `json:"id"`
Email string `json:"email"`
Phone string `json:"phone"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
UpdatedAt time.Time `json:"updatedAt"`
CreatedAt time.Time `json:"createdAt"`
}
-
Clone the repository:
-
Create a
.env
file in the project root -
Start PostgreSQL and create the database.
-
Run the application:
go run .
On the first run, the migration for the
person
table will be applied automatically.
GET /person
or
GET /person?limit=10&offset=0&search=John
GET /person/{id}
POST /person
Content-Type: application/json
{
"email": "[email protected]",
"phone": "+79991234567",
"firstName": "John",
"lastName": "Doe"
}
PUT /person/{id}
Content-Type: application/json
{
"email": "[email protected]",
"phone": "+79991234568",
"firstName": "Peter",
"lastName": "Smith"
}
DELETE /person/{id}