A recopilation of design patterns implemented in Golang. This repository was created with the purpose of understanding the approach taken by Golang language to implement different Design Patterns.
All of the examples included in this project are based on the awsome explanations provided by Refactor Guru.
Server: Golang
- Examples and Implementation of Adapter Design Pattern.
- Examples and Implementation of Bridge Design Pattern.
- Examples and Implementation of Decorator Design Pattern.
- Examples and Implementation of Facade Design Pattern.
- Tests over 70% coverage using golang tests package.
Clone the project
git clone https://github.com/alanmvarela/golang-design-patterns.git
Go to the project directory
cd golang-design-patterns
Run the examples
go run cmd/adapter/adapter.go
go run cmd/bridge/bridge.go
go run cmd/decorator/decorator.go
go run cmd/facade/facade.go
To run tests, run the following command
go test ./... -cover
.
├── cmd
│ ├── adapter
│ │ └── adapter.go
│ ├── bridge
│ │ └── bridge.go
│ ├── decorator
│ │ └── decorator.go
│ └── facade
│ └── facade.go
├── go.mod
├── pkg
│ ├── adapter
│ │ ├── adapters
│ │ │ ├── alpha_client_adapter.go
│ │ │ ├── beta_client_adapter.go
│ │ │ └── client.go
│ │ ├── adapter_test.go
│ │ ├── README.md
│ │ └── third_party
│ │ ├── alpha_client.go
│ │ └── beta_client.go
│ ├── bridge
│ │ ├── clients
│ │ │ ├── alpha_client.go
│ │ │ ├── beta_client.go
│ │ │ ├── client.go
│ │ │ └── client_test.go
│ │ ├── credentials_manager
│ │ │ ├── credential_manager_one.go
│ │ │ ├── credential_manager_two.go
│ │ │ ├── credentials_manager.go
│ │ │ └── credentials_manager_test.go
│ │ ├── logger
│ │ │ ├── logger.go
│ │ │ ├── logger_test.go
│ │ │ ├── log_one.go
│ │ │ └── log_two.go
│ │ └── README.md
│ ├── decorator
│ │ ├── clients
│ │ │ ├── alpha_client.go
│ │ │ ├── beta_client.go
│ │ │ ├── client.go
│ │ │ └── client_test.go
│ │ ├── README.md
│ │ └── service
│ │ ├── service.go
│ │ └── service_test.go
│ └── facade
│ ├── clients
│ │ ├── alpha_client.go
│ │ ├── beta_client.go
│ │ ├── client.go
│ │ └── client_test.go
│ ├── facades
│ │ ├── facades_test.go
│ │ └── serviceFacade.go
│ ├── README.md
│ └── service
│ ├── service.go
│ └── service_test.go
└── README.md
I learnt to identify when to implement each design pattern by applying practical examples.
Also I was able to provide implementations of each pattern while using golang best practices and most accepted approaches related to: error handling, code documentation, project structure and testing.
- Add e.g for one or more implementations of proxy design pattern.
- Add execution of functions with routines and channels for error handling.
- Add mocks for unit testing.