Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/slowhigh/goclean
Go + Clean Archtecture
https://github.com/slowhigh/goclean
clean-architecture clean-code go golang
Last synced: 2 days ago
JSON representation
Go + Clean Archtecture
- Host: GitHub
- URL: https://github.com/slowhigh/goclean
- Owner: slowhigh
- License: mit
- Created: 2024-04-23T00:26:27.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-06-10T01:04:25.000Z (4 months ago)
- Last Synced: 2024-06-19T15:13:27.045Z (4 months ago)
- Topics: clean-architecture, clean-code, go, golang
- Language: Go
- Homepage:
- Size: 103 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goclean
[![Build Status](https://github.com/slowhigh/goclean/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/features/actions)
[![Go Report Card](https://goreportcard.com/badge/github.com/slowhigh/goclean)](https://goreportcard.com/report/github.com/slowhigh/goclean)
[![codebeat badge](https://codebeat.co/badges/20be09ab-0fe5-4789-9bcc-731c193aa59e)](https://codebeat.co/projects/github-com-slowhigh-goclean-main)You can start developing right away in Go (Golang) with a streamlined `Clean Architecture` setup that eliminates unnecessary elements.
## Contents
- [Project structure](#project-structure)
- [Getting started](#getting-started)
- [Make Command](#make-command)
- [References](#references)## Project structure
- [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
- Layer Mapping
- `/infra` ------------------------------------------ "Frameworks and Drivers" Layer
- `/controller` ------------------------------------ "Interface Adapters" Layer
- `/usecase` ---------------------------------------- "Use Cases" Layer
- `/entity` ----------------------------------------- "Entities" Layer
- Crossing boundaries
- [google/wire](https://github.com/google/wire): Compile-time Dependency Injection for Go (DI/IoC)
- Official standard layout (feat. [Go dev team](https://go.dev/doc/go1.4))
- `/internal` ------------------------------------------- [Internal packages](https://go.dev/doc/go1.4#internalpackages)
- De facto standard layout (feat. [golang-standards](https://github.com/golang-standards))
- `/cmd` ------------------------------------------------- [project-layout#cmd](https://github.com/golang-standards/project-layout#cmd)
- `/third_party` ---------------------------------------- [project-layout#third_party](https://github.com/golang-standards/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
```## Getting started
1. Setup PostgreSQL dependency
```bash
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
```2. Download modules
```bash
go mod download
```
3. Run the server
```bash
go run ./cmd/server .
```4. Go to http://localhost:5000/v1/docs/index.html, you to see your Swagger UI for API test
## [Make](https://www.gnu.org/software/make/) Command
- Prerequisites
```bash
# "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 server
- `make di` generate injectors from wire.go
- `make format` formats code
- `make docs` generate swagger file## References
- [Clean Architecture by Robert C. Martin](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html)
- [Go 1.4 Release Notes](https://go.dev/doc/go1.4#internalpackages)
- [golang-standards/project-layout](https://github.com/golang-standards/project-layout)