Example that shows core principles of the Clean Architecture in Golang projects.
- Independent of Frameworks. The architecture does not depend on the existence of some library of feature laden software. This allows you to use such frameworks as tools, rather than having to cram your system into their limited constraints.
- Testable. The business rules can be tested without the UI, Database, Web Server, or any other external element.
- Independent of UI. The UI can change easily, without changing the rest of the system. A Web UI could be replaced with a console UI, for example, without changing the business rules.
- Independent of Database. You can swap out Oracle or SQL Server, for Mongo, BigTable, CouchDB, or something else. Your business rules are not bound to the database.
- Independent of any external agency. In fact your business rules simply don’t know anything at all about the outside world.
More on topic can be found here.
4 Dominant layers:
- Models layer
- Repository layer
- Business Logics layer
- Controller or Handler layer
METHOD | URL | Description |
---|---|---|
http://localhost:8081/users | GetAllUsers | |
http://localhost:8081/user/:id | GetUserByID | |
http://localhost:8081/user:id | DeleteUserByID | |
http://localhost:8081/register | Register | |
http://localhost:8081/login | Login | |
http://localhost:8081/user | Change Password |
{
"first_name" : "Aditya",
"last_name" : "Erlangga",
"email" : "[email protected]",
"password" : "aditya123"
}
{
"email" : "[email protected]",
"password" : "aditya123"
}
{
"id" : 3,
"old_password" : "aditya123",
"new_password" :"hi_everyone!"
}
- go 1.19.1
Do this :
$ git clone https://github.com/adityaerlangga/go-clean-architecture
$ go mod download
$ go run main.go