Skip to content

Latest commit

 

History

History
138 lines (112 loc) · 4.99 KB

README.md

File metadata and controls

138 lines (112 loc) · 4.99 KB

MIT License Coverage Last Commit Go Report Card Go Version

Design Patterns - Golang

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.

Tech Stack

Server: Golang

Features

Run Locally

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

Running Tests

To run tests, run the following command

  go test ./... -cover

Project Structure

.
├── 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

Lessons Learned

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.

Roadmap

  • 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.

Authors