Go Fiber Clean Architecture
CRUD Online Learning Platform with simplified Clean Architecture. Created with Go Fiber - MongoDB - JWT - Cloudinary.
root
= /api/v1
POST /users
{
"email": string,
"password": string
}
POST /auth
{
"email": string,
"password": string
}
Provide Bearer Token
with JWT
for Authorization
to access these APIs. Several APIs can only be accessed by user with admin
role.
root
: /admins
- Register New Admin
POST /
{
"email": string,
"password": string
}
- Get Statistics
GET /statistics
- Soft-Delete User
DELETE /delete_user/:user_id
root
: /courses
- Create New Course
Use multipart form to upload image for this. Upload the file with image
as the key.
POST /
{
"name": string,
"category": string,
"price": int,
"details": string,
"image": File
}
- Update Course
Note: This update method hasn't supported changing image of the course.
PUT /
{
"name": string,
"category": string,
"price": int,
"details": string
}
- Soft-Delete Course
DELETE /:course_id
- Get All Courses
GET /
- Search Courses
POST /search
{
"sort": object,
"filter": object,
"projection": object,
}
This is a general endpoint that can be used to query courses. Here are several examples on how to use this endpoint.
Search all free courses
POST /search
{
"sort": {},
"filter": {
"price": 0
},
"projection": {},
}
Searching certain course by name
POST /search
{
"sort": {},
"filter": {
"name": "fiber-clean"
},
"projection": {},
}
Selecting or removing certain attributes
POST /search
{
"sort": {},
"filter": {
"name": "fiber-clean"
},
"projection": {
"_id": false
"details": true,
"price": true,
"category": true
},
}
Sorting based on certain attribute. Use `-1` to descending sort the key.
POST /search
{
"sort": {
"price": 1
},
"filter": {
"name": "fiber-clean"
},
"projection": {
"_id": false,
"details": true,
"price": true,
"category": true
}
}
- Add environment variables to
.env
as follows:
MONGO_DB=<db>
MONGO_URI=mongodb+srv://<user>:<password>@<cluster>.g8tknrr.mongodb.net/<db>?retryWrites=true&w=majority
CLOUDINARY_CLOUD_NAME=<cloud_name>
CLOUDINARY_API_KEY=<api_key>
CLOUDINARY_API_SECRET=<api_secret>
CLOUDINARY_UPLOAD_FOLDER=<upload_folder>
JWT_AUTH_SECRET=<secret_string>
- Simply execute
go build
orgo run .
to install all dependencies fromgo.mod
and run the server.
- Deeper layer of abstraction if needed.
- Clearer entities, API definition, and database definition.
- Separation of environment variables.
- Security things, like password encryption.
- Deployment: Heroku now requires credit card to use. :(