Skip to content

Commit

Permalink
[update] v.2.0.0 - Clean Architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
bmf-san committed Jun 2, 2019
1 parent 2806997 commit 4913e22
Show file tree
Hide file tree
Showing 42 changed files with 884 additions and 159 deletions.
57 changes: 57 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
jobs-references:
go-container: &go-container
docker:
- image: circleci/golang:1.11.9
environment:
GO111MODULE: "on"
working_directory: /go/src/github.com/github.com/bmf-san/go-api-boilerplate/app
setup_go_packages: &setup_go_packages
run:
name: Setup go packages
command: |
go get -u golang.org/x/lint/golint
go get -u github.com/go-sql-driver/mysql
version: 2
jobs:
mod:
<<: *go-container
steps:
- checkout
- *setup_go_packages
- run:
name: "Run mod"
command: |
go mod download
golint:
<<: *go-container
steps:
- checkout
- *setup_go_packages
- run:
name: Run golint
command: golint ./...
vet:
<<: *go-container
steps:
- checkout
- *setup_go_packages
- run:
name: Run vet
command: go vet ./...
test:
<<: *go-container
steps:
- checkout
- *setup_go_packages
- run:
name: Run test
command: go test -v -race ./...

workflows:
version: 2
build:
jobs:
- golint
- vet
- test
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

[*.go]
indent_style = tab
46 changes: 46 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at bmf.infomation@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
5 changes: 5 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Contributing

Feel free to contribute ! :)

If you have some questions, requests or something, let me know it.
35 changes: 35 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Bug report
about: Create a report to help us improve

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Overview

# Changes

# Impact range

# Operational Requirements

# Related Issue

# Supplement
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
launch.json
/app/.env
launch.json
.DS_STORE
/app/go_api_boilerplate
/app/log/*
!/app/log/.gitkeep
.vscode/
80 changes: 77 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,81 @@ This is an api boilerplate built with golang.

After running docker, you need to execute sql files in `app/database/sql`.

# References
I refered to this repository.
# 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
├── test.log
└── usecases
├── logger.go
├── post_interactor.go
├── post_repository.go
├── user_interactor.go
└── user_repository.go
```

| Layer | Directory | Sub directory |
|----------------------|----------------|--------------------------------------|
| Frameworks & Drivers | infrastructure | database, router, env |
| Interface | interfaces | controllers, database, repositories |
| Usecases | usecases | repositories |
| Entities | domain | ex. user.go |

# API Document
// TODO: This section will be updated the date when ver.3.0.0 will be released.


# Controller method naming rule
Use these word as prefix.

- [github - rymccue/golang-standard-lib-rest-api](https://github.com/rymccue/golang-standard-lib-rest-api)
- index
- Display a listing of the resource.
- show
- Display the specified resource.
- store
- Store a newly created resource in storage.
- update
- Update the specified resource in storage.
- destory
- Remove the specified resource from storage.

# Repository method naming rule
Use these word as prefix.

- get
- add
- update
- delete

# References
- [github - manuelkiessling/go-cleanarchitecture](https://github.com/manuelkiessling/go-cleanarchitecture)
- [github - rymccue/golang-standard-lib-rest-api](https://github.com/rymccue/golang-standard-lib-rest-api)
- [github - hirotakan/go-cleanarchitecture-sample](https://github.com/hirotakan/go-cleanarchitecture-sample)
- [Recruit Technologies - Go言語とDependency Injection](https://recruit-tech.co.jp/blog/2017/12/11/go_dependency_injection/)
- [Clean ArchitectureでAPI Serverを構築してみる](https://qiita.com/hirotakan/items/698c1f5773a3cca6193e)
- [github - ponzu-cms/ponzu](https://github.com/ponzu-cms/ponzu)
- [クリーンアーキテクチャの書籍を読んだのでAPIサーバを実装してみた](https://qiita.com/yoshinori_hisakawa/items/f934178d4bd476c8da32)
- [Go × Clean Architectureのサンプル実装](http://nakawatch.hatenablog.com/entry/2018/07/11/181453)
- [Uncle Bob – Payroll Case Study (A full implementation)](http://cleancodejava.com/uncle-bob-payroll-case-study-full-implementation/)
4 changes: 4 additions & 0 deletions app/.realize.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ schema:
- name: go-api-boilerplate
path: .
commands:
build:
status: true
method: go build -o go_api_boilerplate
run:
status: true
method: ./go_api_boilerplate
watcher:
extensions:
- go
Expand Down
23 changes: 0 additions & 23 deletions app/database/database.go

This file was deleted.

16 changes: 16 additions & 0 deletions app/database/migrations/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE
IF NOT EXISTS `users`
(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR
(255)
) ENGINE = InnoDB DEFAULT CHARSET = utf8
;
CREATE TABLE
IF NOT EXISTS `posts`
(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`user_id` INT UNSIGNED NOT NULL,
`body` TEXT
) ENGINE = InnoDB DEFAULT CHARSET = utf8
;
14 changes: 14 additions & 0 deletions app/database/seeds/faker.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
INSERT INTO users
(name)
VALUES('foo');
INSERT INTO users
(name)
VALUES('bar');

INSERT INTO posts
(user_id, body)
VALUES(1, 'Hello World');
INSERT INTO posts
(user_id, body)
VALUES
(2, 'Hi');
5 changes: 0 additions & 5 deletions app/database/sql/faker.sql

This file was deleted.

10 changes: 0 additions & 10 deletions app/database/sql/schema.sql

This file was deleted.

11 changes: 11 additions & 0 deletions app/domain/post.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package domain

// A Posts belong to the domain layer.
type Posts []Post

// A Post belong to the domain layer.
type Post struct {
ID int `json:"id"`
UserID int `json:"user_id"`
Body string `json:"body"`
}
Loading

0 comments on commit 4913e22

Please sign in to comment.