Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Curated list of Go design patterns, recipes and idioms

License

NotificationsYou must be signed in to change notification settings

tmrts/go-patterns

Repository files navigation

Go Patterns
build-statusawesomelicense

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

Creational Patterns

PatternDescriptionStatus
Abstract FactoryProvides an interface for creating families of releated objects
BuilderBuilds a complex object using simple objects
Factory MethodDefers instantiation of an object to a specialized function for creating instances
Object PoolInstantiates and maintains a group of objects instances of the same type
SingletonRestricts instantiation of a type to one object

Structural Patterns

PatternDescriptionStatus
BridgeDecouples an interface from its implementation so that the two can vary independently
CompositeEncapsulates and provides access to a number of different objects
DecoratorAdds behavior to an object, statically or dynamically
FacadeUses one type as an API to a number of others
FlyweightReuses existing instances of objects with similar/identical state to minimize resource usage
ProxyProvides a surrogate for an object to control it's actions

Behavioral Patterns

PatternDescriptionStatus
Chain of ResponsibilityAvoids coupling a sender to receiver by giving more than object a chance to handle the request
CommandBundles a command and arguments to call later
MediatorConnects objects and acts as a proxy
MementoGenerate an opaque token that can be used to go back to a previous state
ObserverProvide a callback for notification of events/changes to data
RegistryKeep track of all subclasses of a given class
StateEncapsulates varying behavior for the same object based on its internal state
StrategyEnables an algorithm's behavior to be selected at runtime
TemplateDefines a skeleton class which defers some methods to subclasses
VisitorSeparates an algorithm from an object on which it operates

Synchronization Patterns

PatternDescriptionStatus
Condition VariableProvides a mechanism for threads to temporarily give up access in order to wait for some condition
Lock/MutexEnforces mutual exclusion limit on a resource to gain exclusive access
MonitorCombination of mutex and condition variable patterns
Read-Write LockAllows parallel read access, but only exclusive access on write operations to a resource
SemaphoreAllows controlling access to a common resource

Concurrency Patterns

PatternDescriptionStatus
N-BarrierPrevents a process from proceeding until all N processes reach to the barrier
Bounded ParallelismCompletes large number of independent tasks with resource limits
BroadcastTransfers a message to all recipients simultaneously
CoroutinesSubroutines that allow suspending and resuming execution at certain locations
GeneratorsYields a sequence of values one at a time
ReactorDemultiplexes service requests delivered concurrently to a service handler and dispatches them syncronously to the associated request handlers
ParallelismCompletes large number of independent tasks
Producer ConsumerSeparates tasks from task executions

Messaging Patterns

PatternDescriptionStatus
Fan-InFunnels tasks to a work sink (e.g. server)
Fan-OutDistributes tasks among workers (e.g. producer)
Futures & PromisesActs as a place-holder of a result that is initially unknown for synchronization purposes
Publish/SubscribePasses information to a collection of recipients who subscribed to a topic
Push & PullDistributes messages to multiple workers, arranged in a pipeline

Stability Patterns

PatternDescriptionStatus
BulkheadsEnforces a principle of failure containment (i.e. prevents cascading failures)
Circuit-BreakerStops the flow of the requests when requests are likely to fail
DeadlineAllows 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-FastChecks the availability of required resources at the start of a request and fails if the requirements are not satisfied
HandshakingAsks a component if it can take any more load, if it can't, the request is declined
Steady-StateFor every service that accumulates a resource, some other service must recycle that resource

Profiling Patterns

PatternDescriptionStatus
Timing FunctionsWraps a function and logs the execution

Idioms

PatternDescriptionStatus
Functional OptionsAllows creating clean APIs with sane defaults and idiomatic overrides

Anti-Patterns

PatternDescriptionStatus
Cascading FailuresA failure in a system of interconnected parts in which the failure of a part causes a domino effect

About

Curated list of Go design patterns, recipes and idioms

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors11

Languages


[8]ページ先頭

©2009-2025 Movatter.jp