1
0
mirror of https://github.com/tmrts/go-patterns.git synced 2024-11-22 04:56:09 +03:00
Curated list of Go design patterns, recipes and idioms
Go to file
2016-02-20 17:35:39 +02:00
bounded_parallelism Implement parallelism patterns 2016-02-20 17:33:41 +02:00
circuitbreaker Implement circuit-breaker design pattern 2016-02-20 17:33:21 +02:00
fan Add fan-in/out messaging patterns 2016-02-20 17:34:05 +02:00
object_pool Implement object pool pattern 2016-02-20 17:35:17 +02:00
parallelism Implement parallelism patterns 2016-02-20 17:33:41 +02:00
semaphore Update semaphore pattern 2016-02-20 17:32:46 +02:00
singleton Implement singleton pattern 2016-02-20 17:34:36 +02:00
strategy Modify strategy pattern 2016-02-20 17:32:02 +02:00
.gitignore Initial commit 2015-12-15 00:05:06 +02:00
CONTRIBUTING.md Update README and Contribution Guidelines 2015-12-23 15:51:06 +02:00
decorator.go Add decorator pattern 2015-12-23 15:46:27 +02:00
functional_options.go Include more patterns and a logo 2016-01-01 21:06:10 +02:00
gopher.jpg Include more patterns and a logo 2016-01-01 21:06:10 +02:00
LICENSE Initial commit 2015-12-15 00:05:06 +02:00
publish_subscribe.go Include more patterns and a logo 2016-01-01 21:06:10 +02:00
README.md Update README 2016-02-20 17:35:39 +02:00

Go Patterns Travis Widget Awesome Widget License Widget

A curated collection of idiomatic design & application patterns for Go language.

For use cases please see the test files (files suffixed with _test).

Creational Patterns:

Pattern Description
Abstract Factory use a generic function with specific factories
Singleton Restricts instantiation of a class to one object
Builder instead of using multiple constructors, builder object receives parameters and returns constructed objects
Factory Method delegate a specialized function/method to create instances
Lazy Evaluation lazily-evaluated property pattern in Go
Object Pool Instantiates and maintains a group of objects instances of the same type

Structural Patterns:

Pattern Description
Adapter adapt one interface to another using a white-list
Bridge a client-provider middleman to soften interface changes
Composite encapsulate and provide access to a number of different objects
Decorator Adds behavior to an object, statically or dynamically
Facade use one class as an API to a number of others
Flyweight transparently reuse existing instances of objects with similar/identical state
Model View Controller model<->view<->controller (non-strict relationships)
Proxy an object funnels operations to something else

Behavioral Patterns:

Pattern Description
Chain apply a chain of successive handlers to try and process the data
Catalog general methods will call different specialized methods based on construction parameter
Chaining Method continue callback next object method
Command bundle a command and arguments to call later
Mediator an object that knows how to connect other objects and act as a proxy
Memento generate an opaque token that can be used to go back to a previous state
Observer provide a callback for notification of events/changes to data
Registry keep track of all subclasses of a given class
Specification business rules can be recombined by chaining the business rules together using boolean logic
State logic is organized into a discrete number of potential states and the next state that can be transitioned to
Strategy Encapsulates an algorithm inside a struct
Template an object imposes a structure but takes pluggable components
Visitor invoke a callback for all items of a collection

Synchronization Patterns:

Pattern Description
Lock/Mutex Enforces mutual exclusion limit on accessing a resource
Read-Write Lock
Condition Variable
Monitor Combination of mutex and condition variable patterns
Semaphore Allows controlling access to a common resource

Concurrency Patterns:

Pattern Description
Scheduler
Barrier
Producer Consumer
Futures
Broadcast
Multiplex
Generators
Coroutines
Parallelism Completes large number of indenpendent tasks
Bounded Parallelism Completes large number of indenpendent tasks with resource limits

Messaging Patterns: | Fan-In | Funnels tasks to a work sink (e.g. server) | | Fan-Out | Distributes tasks amongs workers | | Publish/Subscribe | Passes information to a collection of recipients who subscribed to a topic | | Request & Reply | | | Push & Pull | |

Stability Patterns:

Pattern Description
Bulkheads
Circuit Breaker Stops the flow of the requests when requests are likely to fail
Deadline
Fail Fast
Handshaking
Steady State

Profiling Patterns:

Pattern Description
Timing Functions Wraps a function and logs the execution

Idioms:

Pattern Description
Functional Options Allows creating clean APIs with sane defaults and idiomatic overrides

Anti-Patterns:

Pattern Description
Cascading Failures

Other Patterns:

Pattern Description

License

Creative Commons License

This work is licensed under a Creative Commons Attribution 4.0 International License.