You can start developing right away in Go (Golang) with a streamlined Clean Architecture
setup that eliminates unnecessary elements.
- Clean Architecture
- Layer Mapping
/infra
------------------------------------------ "Frameworks and Drivers" Layer/controller
------------------------------------ "Interface Adapters" Layer/usecase
---------------------------------------- "Use Cases" Layer/entity
----------------------------------------- "Entities" Layer
- Crossing boundaries
- google/wire: Compile-time Dependency Injection for Go (DI/IoC)
- Layer Mapping
- Official standard layout (feat. Go dev team)
/internal
------------------------------------------- Internal packages
- De facto standard layout (feat. golang-standards)
/cmd
------------------------------------------------- project-layout#cmd/third_party
---------------------------------------- project-layout#third_party
├── cmd --------------------------------------------- De facto standard layout
│ └── server
│ ├── main.go
│ ├── wire_gen.go ------------------------------- Code generated by "Google/Wire".
│ └── wire.go ----------------------------------- Core code of "Google/Wire"
│
├── infra ------------------------------------------- "Frameworks and Drivers" Layer
│ ├── infra.go
│ ├── config
│ │ ├── config.go
│ │ └── config.json
│ ├── database
│ │ ├── database.go
│ │ └── repository
│ │ └── memo_repo.go
│ └── router
│ ├── router.go
│ ├── handler
│ │ └── memo_handler.go
│ └── middleware
│ └── middleware.go
│
├── internal ---------------------------------------- Official standard layout
│ ├── controller ----------------------------------- "Interface Adapters" Layer
│ │ ├── controller.go
│ │ └── rest
│ │ ├── dto
│ │ │ ├── memo_dto
│ │ │ │ ├── memo_create_dto.go
│ │ │ │ ├── memo_delete_dto.go
│ │ │ │ ├── memo_find_all_dto.go
│ │ │ │ ├── memo_find_one_dto.go
│ │ │ │ └── memo_update_dto.go
│ │ │ └── pagination_dto.go
│ │ └── memo_controller.go
│ ├── usecase -------------------------------------- "Use Cases" Layer
│ │ ├── usecase.go
│ │ └── memo
│ │ └── memo_ucase.go
│ └── entity --------------------------------------- "Entities" Layer
│ └── memo.go
│
└── third_party ------------------------------------- De facto standard layout
└── docs
├── docs.go
├── swagger.json
└── swagger.yaml
-
Setup PostgreSQL dependency
docker run -d --name goclean --env=POSTGRES_USER=goclean --env=POSTGRES_PASSWORD=goclean1! --env=POSTGRES_DB=goclean --env=TIMEZONE=Asia/Seoul -p 5432:5432 postgres
-
Download modules
go mod download
-
Run the server
go run ./cmd/server .
-
Go to http://localhost:5000/v1/docs/index.html, you to see your Swagger UI for API test
Make Command
-
Prerequisites
# "google/wire" module go install github.com/google/wire/cmd/wire@latest # "swaggo/swag" module go install github.com/swaggo/swag/cmd/swag@latest # "golang.org/x/tools" module go install golang.org/x/tools/cmd/goimports@latest
-
Command
make run
run the servermake di
generate injectors from wire.gomake format
formats codemake docs
generate swagger file