Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chkilel/fiberent
Clean architecture implementation in Go with Fiber and Ent ORM
https://github.com/chkilel/fiberent
Last synced: about 2 months ago
JSON representation
Clean architecture implementation in Go with Fiber and Ent ORM
- Host: GitHub
- URL: https://github.com/chkilel/fiberent
- Owner: chkilel
- Created: 2022-06-19T15:19:23.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-07-17T10:27:29.000Z (over 2 years ago)
- Last Synced: 2024-06-20T12:36:33.314Z (7 months ago)
- Language: Go
- Size: 117 KB
- Stars: 12
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FiberEnt | *Clean Architecture in Go* 🎉
FiberEnt is a clean architecture implementation in Go with the following frameworks:
- [Fiber](https://github.com/gofiber/fiber) 🚀 is an Express inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go.
- [Ent](https://github.com/ent/ent) 🎉 is an entity framework for Go,
Simple, yet powerful ORM for modeling and querying data.
## Start development
> Docker must be installed.Start docker container
```bash
make docker-dev # or docker-compose up
```
then migrate database```bash
make migrate
```# Steps to create a new entity
Install **Ent** entity framework, check out [https://entgo.io/docs/getting-started#installation](https://entgo.io/docs/getting-started#installation) for more information.
> **In the following example, we will create a new entity called `User`.**
1. Create an entity schema
```bash
go run entgo.io/ent/cmd/ent init User # User is the name of the entity
```2. Open up `/ent/schema/user.go`
- add your fields to the User schema, check **[Ent Field creation](https://entgo.io/docs/schema-fields)** for more information.
- add your edges to the User schema, check **[Ent Edges creation](https://entgo.io/docs/schema-edges)** for more information.3. Run go generate from the the project root directory.
```bash
go generate ./ent
```4. Create `user entity` file `/entity/user.go`.
5. Define the `user` repository (Reader and Writer) Interface and the usecase (service) Interface in the `/usecase/user` folder
6. Create the User **service** Implementation of the `Usecase` interface in the `/usecase/user/service.go`.
7. Create the User **repository** implementation of the `Repository` interface in the `/infrastructure/ent/repository/user_ent.go`.
8. Add the handler `/api/handler/user.go` and the presenter `/api/presenter/user.go` files.
9. Update `/api/main.go` file with the new endpoint.
## API requests
### Add a user
```
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"
}'
```
### Update a user```
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"
}'
```### Get a user
```
curl "http://localhost:3030/api/v1/users/[USER_ID]" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json'
```### Delete a user
```
curl -X "DELETE" "http://localhost:3030/api/v1/users/[USER_ID]" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json'
```### List all users
```
curl "http://localhost:3030/api/v1/users" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json'
```