Sample Golang Clean Architecture for REST API
- Web Framework: Gin
- Database: MySQL
- Cache: Redis
- Config file: Viper
REST API for posting some content/message with CRUD (Create, Read, Update, Delete) capability added with caching feature.
Based on repository pattern, this project use:
- Repository layer: For accessing db in the behalf of project to store/update/delete data
- Usecase layer: Contains set of logic/action needed to process data/orchestrate those data
- Models layer: Contains set of entity/actual data attribute
- Controller layer: Acts to mapping users input/request and presented it back to user as relevant responses
Creates a new post
{
"title": "testing",
"content": "contents",
"image_url": "http://an.image",
"category": "testing_post"
}
Get all posts
[
{
"id": 1,
"title": "testing",
"slug": "testing-1",
"content": "contents",
"image_url": "http://an.image",
"category": "testing_post"
}
]
Get post by id
{
"id": 1,
"title": "testing",
"slug": "testing-1",
"content": "contents",
"image_url": "http://an.image",
"category": "testing_post"
}
Get post by slug
{
"id": 1,
"title": "testing",
"slug": "testing-1",
"content": "contents",
"image_url": "http://an.image",
"category": "testing_post"
}
Get post by title
{
"id": 1,
"title": "testing",
"slug": "testing-1",
"content": "contents",
"image_url": "http://an.image",
"category": "testing_post"
}
Delete post by ID
Update post by ID
{
"id": 1,
"title": "testing",
"slug": "testing-1",
"content": "contents",
"image_url": "http://an.image",
"category": "testing_post"
}
{
"message": "Post successfully updated!"
}