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-03 01:32:15 +08:00
ardan_labs/thread_pooling Added comments 2018-03-01 16:05:15 +10:00
array [DEV] Added benchmark example 2018-07-02 16:35:03 +10:00
behavioral Merge https://github.com/weichou1229/go-patterns 2020-05-03 01:32:15 +08:00
benchmark [DEV] Added benchmark example 2018-07-02 16:35:03 +10:00
channel Abstract factory pattern 2018-01-14 15:43:41 +10:00
cmd cmd examplte 2018-01-21 20:53:34 +10:00
concurrency Merge https://github.com/weichou1229/go-patterns 2020-05-03 01:32:15 +08:00
creational Abstract factory pattern 2018-01-14 15:43:41 +10:00
defer added defer with pointer and struct 2018-01-12 15:31:09 +10:00
for-range-semantics resource leak go routine demo 2018-01-16 18:59:46 +10:00
functional_programming/ch01 cache added 2018-04-19 21:50:54 +10:00
functions/first_class first class function example 2018-01-11 15:19:31 +10:00
go_design_pattern_book added builder pattern 2018-01-10 21:42:52 +10:00
graphql added graphql 2018-01-22 22:34:12 +10:00
idiom demo on how to output string 2018-01-19 15:17:32 +10:00
init added init and sem 2017-11-22 16:42:17 +10:00
interface-semantics added lexical demo 2018-01-16 11:32:21 +10:00
ioreader cmd examplte 2018-01-21 20:53:34 +10:00
master_concurrent_go/ch01 list thread 2018-04-28 14:08:44 +10:00
messaging messaging/publish-subscribe: fix channel read 2016-09-20 22:17:06 +03:00
openclose Added oct cat example 2018-03-10 23:34:31 +10:00
phrasebook/ch04 [DEV] Zero initialization 2018-04-14 22:41:23 +10:00
playground Merge https://github.com/weichou1229/go-patterns 2020-05-03 01:32:15 +08:00
profiling profiling/timing: elaborate on deferred function evaluation 2017-02-27 10:05:43 +03:00
semaphore added init and sem 2017-11-22 16:42:17 +10:00
shadow [DEV] Added benchmark example 2018-07-02 16:35:03 +10:00
stability stability/circuit-breaker: fix broken link 2016-10-20 06:43:10 +03:00
structural update code 2019-05-05 23:42:21 +08:00
synchronization Rewrite semaphore pattern 2016-04-16 17:37:17 +03:00
the_go_programming_language/ch04 hello world with job example 2018-04-27 22:29:19 +10:00
urfavecli added sem simple worker pool 2017-12-03 15:50:40 +10:00
workerpool added comments for worker pool 2017-11-07 14:48:16 +10: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
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 https://github.com/weichou1229/go-patterns 2020-05-03 01:32:15 +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.

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 âœ

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 syncronously 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 âœ