FiberEnt is a clean architecture implementation in Go with the following frameworks:
- Fiber 🚀 is an Express inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go.
- Ent 🎉 is an entity framework for Go, Simple, yet powerful ORM for modeling and querying data.
Docker must be installed.
Start docker container
make docker-dev # or docker-compose up
then migrate database
make migrate
Install Ent entity framework, check out https://entgo.io/docs/getting-started#installation for more information.
In the following example, we will create a new entity called
User
.
-
Create an entity schema
go run entgo.io/ent/cmd/ent init User # User is the name of the entity
-
Open up
<project>/ent/schema/user.go
- add your fields to the User schema, check Ent Field creation for more information.
- add your edges to the User schema, check Ent Edges creation for more information.
-
Run go generate from the the project root directory.
go generate ./ent
-
Create
user entity
file<project>/entity/user.go
. -
Define the
user
repository (Reader and Writer) Interface and the usecase (service) Interface in the<project>/usecase/user
folder -
Create the User service Implementation of the
Usecase
interface in the<project>/usecase/user/service.go
. -
Create the User repository implementation of the
Repository
interface in the<project>/infrastructure/ent/repository/user_ent.go
. -
Add the handler
<project>/api/handler/user.go
and the presenter<project>/api/presenter/user.go
files. -
Update
<project>/api/main.go
file with the new endpoint.
curl -X "POST" "http://localhost:3030/api/v1/users" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d $'{
"email": "[email protected]",
"first_name": "Adil",
"last_name": "Chehabi",
"password": "password"
}'
curl -X "POST" "http://localhost:3030/api/v1/users/[USER_ID]" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d $'{
"email": "[email protected]",
"first_name": "Adil",
"last_name": "Chkilel",
"password": "password"
}'
curl "http://localhost:3030/api/v1/users/[USER_ID]" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json'
curl -X "DELETE" "http://localhost:3030/api/v1/users/[USER_ID]" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json'
curl "http://localhost:3030/api/v1/users" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json'