-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf8b520
commit 5d1cbdb
Showing
42 changed files
with
179 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Clean Architecture checker for Golang | ||
|
||
go-cleanarch was created to keep Clean Architecture rules, | ||
like a _The Dependency Rule_ and _interaction between modules_ in your Go projects. | ||
More about Clean Architecture you can read in [Uncle's Bob article](https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html). | ||
|
||
![Clean Architecture](docs/go-cleanarch.png) | ||
|
||
## Installing | ||
|
||
go get github.com/roblaszczak/go-cleanarch | ||
|
||
_go-cleanarch was only tested on Linux and also should work on OS X. | ||
Probably it doesn't work well on Windows._ | ||
|
||
## Running | ||
|
||
To run in current directory: | ||
|
||
cleanarch | ||
|
||
To run in provided directory | ||
|
||
cleanarch go/src/github.com/roblaszczak/awesome-cms | ||
|
||
### Project schema requirements | ||
|
||
go-cleanarch assumes this files structure: | ||
|
||
[GOPATH]/[PACKAGE_NAME]/[LAYER_NAME] | ||
|
||
or | ||
|
||
[GOPATH]/[PACKAGE_NAME]/[MODULE_NAME]/[LAYER_NAME] | ||
|
||
For example | ||
|
||
* go/src/github.com/roblaszczak/awesome-app | ||
* auth | ||
* domain | ||
* application | ||
* interfaces | ||
* content | ||
* domain | ||
* application | ||
* interfaces | ||
* frontend | ||
* domain | ||
* application | ||
* interfaces | ||
|
||
For examples please go to [examples](examples/) directory, | ||
with contains examples of valid and invalid architectures. | ||
|
||
For more informations about Clean Architecture please read [Uncle's Bob article](https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html) | ||
|
||
## Running the tests | ||
|
||
make test | ||
|
||
## And coding style tests | ||
|
||
make qa | ||
|
||
## Contributing | ||
|
||
Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us. | ||
|
||
## Versioning | ||
|
||
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags). | ||
|
||
## Credits | ||
|
||
Made without love by Robert Laszczak </3 | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Invalid `app` to `domain` import | ||
|
||
![Schema](schema.png) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package domain | ||
|
||
import "github.com/roblaszczak/go-cleanarch/examples/invalid-app-to-domain-import/app" | ||
|
||
type Product struct { | ||
Price app.Price | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Invalid cross modules deps | ||
|
||
![Schema](schema.png) | ||
|
||
In this example modules are interacting directly | ||
(without using `interfaces` and `infrastructure` layers). |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app | ||
|
||
import "github.com/roblaszczak/go-cleanarch/examples/invalid-cross-module-deps/forum/post/app" | ||
|
||
type User struct { | ||
Posts []app.Post | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Invalid `infrastructure` in domain `import` | ||
|
||
![Schema](schema.png) |
2 changes: 1 addition & 1 deletion
2
...id-infra-in-domain-import/domain/order.go → ...id-infra-in-domain-import/domain/order.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Invalid cross module deps | ||
|
||
![Schema](schema.png) |
7 changes: 7 additions & 0 deletions
7
examples/valid-cross-module-deps/cms/auth/interfaces/access.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package interfaces | ||
|
||
import "github.com/roblaszczak/go-cleanarch/examples/valid-cross-module-deps/cms/auth/usecases" | ||
|
||
func CheckAccess(username string) bool { | ||
return usecases.LoginAccessChecker(username) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package usecases | ||
|
||
func LoginAccessChecker(username string) bool { | ||
return username == "admin" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/roblaszczak/go-cleanarch/examples/valid-cross-module-deps/cms/content/infrastructure" | ||
"github.com/roblaszczak/go-cleanarch/examples/valid-cross-module-deps/cms/content/usecases" | ||
) | ||
|
||
func main() { | ||
usecases.AddArticle{infrastructure.AuthModuleAuthChecker{}}.AddArticle("admin", "test article") | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/valid-cross-module-deps/cms/content/infrastructure/auth.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package infrastructure | ||
|
||
import ( | ||
"github.com/roblaszczak/go-cleanarch/examples/valid-cross-module-deps/cms/auth/interfaces" | ||
) | ||
|
||
type AuthModuleAuthChecker struct{} | ||
|
||
func (a AuthModuleAuthChecker) CheckAuth(username string) bool { | ||
return interfaces.CheckAccess(username) | ||
} |
24 changes: 24 additions & 0 deletions
24
examples/valid-cross-module-deps/cms/content/usecases/add_article.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package usecases | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type AuthChecker interface { | ||
CheckAuth(username string) bool | ||
} | ||
|
||
type AddArticle struct { | ||
AuthChecker AuthChecker | ||
} | ||
|
||
func (c AddArticle) AddArticle(username string, title string) error { | ||
if !c.AuthChecker.CheckAuth(username) { | ||
return fmt.Errorf("user %s is not allowed to add article", username) | ||
} | ||
|
||
// todo - some article adding logic | ||
fmt.Printf("added %s article by %s\n", title, username) | ||
|
||
return nil | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Simple valid architecture | ||
|
||
![Schema](schema.png) |
2 changes: 1 addition & 1 deletion
2
tests/valid-simple/app/payment.go → examples/valid-simple/app/payment.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
7 changes: 0 additions & 7 deletions
7
tests/invalid-import-between-modules-apps/forum/user/app/user.go
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
tests/valid-cross-module-deps/cms/content/domain/authchecker.go
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
tests/valid-cross-module-deps/cms/content/infrastructure/auth.go
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
tests/valid-cross-module-deps/cms/content/usecases/checkaccess.go
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.