Collections of Go patterns based on tmrts/go-patterns, But merged with other awesome forks and more improvoments. https://crazybber.github.io/awesome-patterns/
Go to file
2020-05-27 21:53:28 +08:00
behavioral Update README.md 2020-05-11 21:28:07 +08:00
channel move pubsub to messaging 2020-05-14 23:27:20 +08:00
concurrency move pool to workerpool 2020-05-14 23:28:10 +08:00
creational merge singleton pattern 2020-05-27 21:53:18 +08:00
data gather data catalog 2020-05-27 21:52:46 +08:00
functions gather function catalog 2020-05-09 16:19:39 +08:00
idiom demo on how to output string 2018-01-19 15:17:32 +10:00
messaging move pubsub to messaging 2020-05-14 23:27:20 +08:00
openclose Added oct cat example 2018-03-10 23:34:31 +10:00
playground merge singleton pattern 2020-05-27 21:53:18 +08:00
profiling merge singleton pattern 2020-05-27 21:53:18 +08:00
shadow [DEV] Added benchmark example 2018-07-02 16:35:03 +10:00
stability Update circuit-breaker.md 2020-05-22 14:24:57 +08:00
structural organize structural patterns 2020-05-08 17:07:20 +08:00
synchronization move semaphore/waitgroup to synchronization 2020-05-14 23:27:55 +08:00
workerpool move pool to workerpool 2020-05-14 23:28:10 +08:00
.gitignore Merge https://github.com/weichou1229/go-patterns 2020-05-03 01:32:15 +08:00
.travis.yml travis-ci: configure continuous deployments 2016-10-20 06:31:00 +03:00
book.json SUMMARY: index pattern sections 2016-09-13 17:32:41 +03:00
CONTRIBUTING.md CONTRIBUTING: extend the contribution guidelines 2016-09-06 19:27:15 +03:00
go.mod update mod 2020-05-27 21:53:28 +08:00
go.sum update mod 2020-05-27 21:53:28 +08:00
gopher.png *: polish the logo 2017-03-06 16:26:19 +03:00
LICENSE LICENSE: remove the appendix at the end of the license 2017-02-22 19:18:01 +03:00
README.md merge singleton pattern 2020-05-27 21:53:18 +08:00
SUMMARY.md test goroutine 2018-09-07 21:11:24 +08:00

Go Patterns
build-status awesome license

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

a fork of tmrts/go-patterns but merged in with other awesome forks. can go with patterns-in-examples

Merged Repos

Creational Patterns

Pattern Description Status
Abstract Factory Provides an interface for creating families of releated objects
Builder Builds a complex object using simple objects
Factory Method Defers instantiation of an object to a specialized function for creating instances
Object Pool Instantiates and maintains a group of objects instances of the same type
Singleton Restricts instantiation of a type to one object

Structural Patterns

Pattern Description Status
Bridge Decouples an interface from its implementation so that the two can vary independently
Composite Encapsulates and provides access to a number of different objects
Decorator Adds behavior to an object, statically or dynamically
Facade Uses one type as an API to a number of others
Flyweight Reuses existing instances of objects with similar/identical state to minimize resource usage
Proxy Provides a surrogate for an object to control it's actions

Behavioral Patterns

Pattern Description Status
Chain of Responsibility Avoids coupling a sender to receiver by giving more than object a chance to handle the request
Command Bundles a command and arguments to call later
Mediator Connects objects and acts 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
State Encapsulates varying behavior for the same object based on its internal state
Strategy Enables an algorithm's behavior to be selected at runtime
Template Defines a skeleton class which defers some methods to subclasses
Visitor Separates an algorithm from an object on which it operates
Interpreter interpret your own language or composed commands

Synchronization Patterns

Pattern Description Status
Condition Variable Provides a mechanism for threads to temporarily give up access in order to wait for some condition
Lock/Mutex Enforces mutual exclusion limit on a resource to gain exclusive access
Monitor Combination of mutex and condition variable patterns
Read-Write Lock Allows parallel read access, but only exclusive access on write operations to a resource
Semaphore Allows controlling access to a common resource

Concurrency Patterns

Pattern Description Status
N-Barrier Prevents a process from proceeding until all N processes reach to the barrier
Bounded Parallelism Completes large number of independent tasks with resource limits
Broadcast Transfers a message to all recipients simultaneously
Coroutines Subroutines that allow suspending and resuming execution at certain locations
Generators Yields a sequence of values one at a time
Reactor Demultiplexes service requests delivered concurrently to a service handler and dispatches them synchronously to the associated request handlers
Parallelism Completes large number of independent tasks
Producer Consumer Separates tasks from task executions

Messaging Patterns

Pattern Description Status
Fan-In Funnels tasks to a work sink (e.g. server)
Fan-Out Distributes tasks among workers (e.g. producer)
Futures & Promises Acts as a place-holder of a result that is initially unknown for synchronization purposes
Publish/Subscribe Passes information to a collection of recipients who subscribed to a topic
Push & Pull Distributes messages to multiple workers, arranged in a pipeline

Stability Patterns

Pattern Description Status
Bulkheads Enforces a principle of failure containment (i.e. prevents cascading failures)
Circuit-Breaker Stops the flow of the requests when requests are likely to fail
Deadline Allows clients to stop waiting for a response once the probability of response becomes low (e.g. after waiting 10 seconds for a page refresh)
Fail-Fast Checks the availability of required resources at the start of a request and fails if the requirements are not satisfied
Handshaking Asks a component if it can take any more load, if it can't, the request is declined
Steady-State For every service that accumulates a resource, some other service must recycle that resource

Profiling Patterns

Pattern Description Status
Timing Functions Wraps a function and logs the execution

Idioms

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

Anti-Patterns

Pattern Description Status
Cascading Failures A failure in a system of interconnected parts in which the failure of a part causes a domino effect

A pattern implementation

go-patterns-in-examples