module
Version:
v0.0.0-...-dca2a0b
Opens a new window with list of versions in this module.
Published: May 1, 2023
License: Apache-2.0
Opens a new window with license information.
README
¶
Go Patterns
A curated collection of idiomatic design & application patterns for Go language.
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 |
✔ |
Adapter |
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 |
A pattern implementation
go-pattern-examples
Directories
¶
behavioral
|
|
|
|
command
命令模式(command pattern)主要解耦了行为和接收者,使之可以任意组合为一个完整的命令,并在合适的时候被调用 主要分为四个部分,command ,ConcreteCommand ,receiver ,invoker.
|
命令模式(command pattern)主要解耦了行为和接收者,使之可以任意组合为一个完整的命令,并在合适的时候被调用 主要分为四个部分,command ,ConcreteCommand ,receiver ,invoker. |
|
|
mediator
中介者模式(mediator pattern) 当两个对象存在复杂的依赖关系时,考虑增加一个中介者使之解耦,使他们不需要进行显式的引用.
|
中介者模式(mediator pattern) 当两个对象存在复杂的依赖关系时,考虑增加一个中介者使之解耦,使他们不需要进行显式的引用. |
memento
备忘录模式 memento pattern 在不影响原结构封装的情况下,能够暂时保存一个结构的状态,并能够恢复 这里是一个游戏存档的例子,尝试保存玩家当前位置,并在读档的时候恢复
|
备忘录模式 memento pattern 在不影响原结构封装的情况下,能够暂时保存一个结构的状态,并能够恢复 这里是一个游戏存档的例子,尝试保存玩家当前位置,并在读档的时候恢复 |
observer
Package main serves as an example application that makes use of the observer pattern.
|
Package main serves as an example application that makes use of the observer pattern. |
|
|
|
|
state
状态模式 state pattern.
|
状态模式 state pattern. |
|
|
|
存疑的部分. |
|
访问者模式 visitor pattern. |
channel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
creational
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data
|
|
|
|
|
|
idiom
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stability
|
|
deadline
Package deadline implements the deadline (also known as "timeout") resiliency pattern for Go.
|
Package deadline implements the deadline (also known as "timeout") resiliency pattern for Go. |
structural
|
|
|
桥接模式 bridge pattern. |
|
组合模式 composite pattern. |
|
|
|
外观模式 facade pattern. |
|
享元模式 flyweight pattern. |
|
|
synchronization
|
|
|
|
|
|
|
|
|
|
|
|
ardan_labs_worker_pool
Package workpool implements a pool of go routines that are dedicated to processing work that is posted into the pool.
|
Package workpool implements a pool of go routines that are dedicated to processing work that is posted into the pool. |
|
|
Click to show internal directories.
Click to hide internal directories.