go-clean-architecture-web-application-boilerplate
A web application boilerplate built with go and clean architecture. Most of this application built by standard libray.
Get Started
cp app/.env_example app/.env
docker-compose build
docker-compose up
After running docker, you need to execute sql files in app/database/sql
.
Architecture
app
โโโ database
โย ย โโโ migrations
โย ย โย ย โโโ schema.sql
โย ย โโโ seeds
โย ย โโโ faker.sql
โโโ domain
โย ย โโโ post.go
โย ย โโโ user.go
โโโ infrastructure
โย ย โโโ env.go
โย ย โโโ logger.go
โย ย โโโ router.go
โย ย โโโ sqlhandler.go
โโโ interfaces
โย ย โโโ post_controller.go
โย ย โโโ post_repository.go
โย ย โโโ sqlhandler.go
โย ย โโโ user_controller.go
โย ย โโโ user_repository.go
โโโ log
โย ย โโโ access.log
โย ย โโโ error.log
โโโ main.go
โโโ usecases
โโโ logger.go
โโโ post_interactor.go
โโโ post_repository.go
โโโ user_interactor.go
โโโ user_repository.go
8 directories, 22 files
Layer | Directory |
---|---|
Frameworks & Drivers | infrastructure |
Interface | interfaces |
Usecases | usecases |
Entities | domain |
API
ENDPOINT | HTTP Method | Parameters |
---|---|---|
/users | GET | |
/user | GET | ?id=[int] |
/posts | GET | |
/post | POST | |
/post | DELETE | ?id=[int] |
Controller method naming rule
Controller Method | HTTP Method | Description |
---|---|---|
Index | GET | Display a listing of the resource |
Store | POST | Store a newly created resource in storage |
Show | GET | Display the specified resource |
Update | PUT/PATCH | Update the specified resource in storage |
Destroy | DELETE | Remove the specified resource from storage |
Repository method naming rule
Repository Method | Description |
---|---|
FindByXX | Returns the entity identified by the given XX |
FindAll | Returns all entities |
Save | Saves the given entity |
SaveByXX | Saves the given entity identified by the given XX |
DeleteByXX | Deletes the entity identified by the given XX |
Count | Returns the number of entities |
ExistsBy | Indicates whether an entity with the given ID exists |
cf. Spring Data JPA - Reference Documentation
Tests
I have no tests because of my laziness, but I will prepare tests in github - gobel-api which is a my more practical clean architecture application with golang.
References
- github - manuelkiessling/go-cleanarchitecture
- github - rymccue/golang-standard-lib-rest-api
- github - hirotakan/go-cleanarchitecture-sample
- Recruit Technologies - Go่จ่ชใจDependency Injection
- Clean ArchitectureใงAPI Serverใๆง็ฏใใฆใฟใ
- github - ponzu-cms/ponzu
- ใฏใชใผใณใขใผใญใใฏใใฃใฎๆธ็ฑใ่ชญใใ ใฎใงAPIใตใผใใๅฎ่ฃ ใใฆใฟใ
- Go ร Clean Architectureใฎใตใณใใซๅฎ่ฃ
- Uncle Bob โ Payroll Case Study (A full implementation)