Skip to content

Commit fc31dc2

Browse files
Surendra RaikaSurendra Raika
authored andcommitted
Add modern bold theme with hero landing page and difficulty badges
Redesign the mdBook site with a Supabase/Linear-inspired aesthetic: - Custom CSS with Go-branded color palette (cyan/magenta/yellow) - Gradient H1 headings, styled code blocks, tables, and sidebar - Hero landing page with gopher, stat badges, CTA buttons, and 9-category card grid with hover effects - Difficulty badges (Easy/Medium/Hard) on all 48 pattern pages - Google Fonts (Inter + JetBrains Mono) for modern typography - Full light/dark theme support across all 5 mdBook themes - Responsive layout with mobile-friendly card stacking - Emoji category headers in sidebar navigation
1 parent 5a5a9e1 commit fc31dc2

54 files changed

Lines changed: 755 additions & 173 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 108 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,108 @@
1-
<p align="center">
2-
<img src="/gopher.png" height="400">
3-
<h1 align="center">
4-
Go Design Patterns
5-
<br>
6-
<a href="https://github.com/RaikaSurendra/go-design-patterns/blob/master/LICENSE"><img alt="license" src="https://img.shields.io/badge/license-Apache%20License%202.0-E91E63.svg?style=flat-square" /></a>
7-
<a href="https://github.com/RaikaSurendra/go-design-patterns/issues"><img alt="issues" src="https://img.shields.io/github/issues/RaikaSurendra/go-design-patterns?style=flat-square" /></a>
8-
</h1>
9-
</p>
10-
11-
A curated collection of idiomatic design & application patterns for Go language.
12-
13-
> **Note:** This is an actively maintained fork of [tmrts/go-patterns](https://github.com/tmrts/go-patterns), which has been inactive since 2017. The goal is to complete all missing pattern implementations, fix existing bugs, and keep the content up to date with modern Go. Contributions are welcome!
14-
15-
## Creational Patterns
16-
17-
| Pattern | Description | Status |
18-
|:-------:|:----------- |:------:|
19-
| [Abstract Factory](/creational/abstract_factory.md) | Provides an interface for creating families of releated objects ||
20-
| [Builder](/creational/builder.md) | Builds a complex object using simple objects ||
21-
| [Factory Method](/creational/factory.md) | Defers instantiation of an object to a specialized function for creating instances ||
22-
| [Object Pool](/creational/object-pool.md) | Instantiates and maintains a group of objects instances of the same type ||
23-
| [Singleton](/creational/singleton.md) | Restricts instantiation of a type to one object ||
24-
25-
## Structural Patterns
26-
27-
| Pattern | Description | Status |
28-
|:-------:|:----------- |:------:|
29-
| [Bridge](/structural/bridge.md) | Decouples an interface from its implementation so that the two can vary independently ||
30-
| [Composite](/structural/composite.md) | Encapsulates and provides access to a number of different objects ||
31-
| [Decorator](/structural/decorator.md) | Adds behavior to an object, statically or dynamically ||
32-
| [Facade](/structural/facade.md) | Uses one type as an API to a number of others ||
33-
| [Flyweight](/structural/flyweight.md) | Reuses existing instances of objects with similar/identical state to minimize resource usage ||
34-
| [Proxy](/structural/proxy.md) | Provides a surrogate for an object to control it's actions ||
35-
36-
## Behavioral Patterns
37-
38-
| Pattern | Description | Status |
39-
|:-------:|:----------- |:------:|
40-
| [Chain of Responsibility](/behavioral/chain_of_responsibility.md) | Avoids coupling a sender to receiver by giving more than object a chance to handle the request ||
41-
| [Command](/behavioral/command.md) | Bundles a command and arguments to call later ||
42-
| [Mediator](/behavioral/mediator.md) | Connects objects and acts as a proxy ||
43-
| [Memento](/behavioral/memento.md) | Generate an opaque token that can be used to go back to a previous state ||
44-
| [Observer](/behavioral/observer.md) | Provide a callback for notification of events/changes to data ||
45-
| [Registry](/behavioral/registry.md) | Keep track of all subclasses of a given class ||
46-
| [State](/behavioral/state.md) | Encapsulates varying behavior for the same object based on its internal state ||
47-
| [Strategy](/behavioral/strategy.md) | Enables an algorithm's behavior to be selected at runtime ||
48-
| [Template](/behavioral/template.md) | Defines a skeleton class which defers some methods to subclasses ||
49-
| [Visitor](/behavioral/visitor.md) | Separates an algorithm from an object on which it operates ||
50-
51-
## Synchronization Patterns
52-
53-
| Pattern | Description | Status |
54-
|:-------:|:----------- |:------:|
55-
| [Condition Variable](/synchronization/condition_variable.md) | Provides a mechanism for threads to temporarily give up access in order to wait for some condition ||
56-
| [Lock/Mutex](/synchronization/mutex.md) | Enforces mutual exclusion limit on a resource to gain exclusive access ||
57-
| [Monitor](/synchronization/monitor.md) | Combination of mutex and condition variable patterns ||
58-
| [Read-Write Lock](/synchronization/read_write_lock.md) | Allows parallel read access, but only exclusive access on write operations to a resource ||
59-
| [Semaphore](/synchronization/semaphore.md) | Allows controlling access to a common resource ||
60-
61-
## Concurrency Patterns
62-
63-
| Pattern | Description | Status |
64-
|:-------:|:----------- |:------:|
65-
| [N-Barrier](/concurrency/barrier.md) | Prevents a process from proceeding until all N processes reach to the barrier ||
66-
| [Bounded Parallelism](/concurrency/bounded_parallelism.md) | Completes large number of independent tasks with resource limits ||
67-
| [Broadcast](/concurrency/broadcast.md) | Transfers a message to all recipients simultaneously ||
68-
| [Coroutines](/concurrency/coroutine.md) | Subroutines that allow suspending and resuming execution at certain locations ||
69-
| [Generators](/concurrency/generator.md) | Yields a sequence of values one at a time ||
70-
| [Reactor](/concurrency/reactor.md) | Demultiplexes service requests delivered concurrently to a service handler and dispatches them syncronously to the associated request handlers ||
71-
| [Parallelism](/concurrency/parallelism.md) | Completes large number of independent tasks ||
72-
| [Producer Consumer](/concurrency/producer_consumer.md) | Separates tasks from task executions ||
73-
74-
## Messaging Patterns
75-
76-
| Pattern | Description | Status |
77-
|:-------:|:----------- |:------:|
78-
| [Fan-In](/messaging/fan_in.md) | Funnels tasks to a work sink (e.g. server) ||
79-
| [Fan-Out](/messaging/fan_out.md) | Distributes tasks among workers (e.g. producer) ||
80-
| [Futures & Promises](/messaging/futures_promises.md) | Acts as a place-holder of a result that is initially unknown for synchronization purposes ||
81-
| [Publish/Subscribe](/messaging/publish_subscribe.md) | Passes information to a collection of recipients who subscribed to a topic ||
82-
| [Push & Pull](/messaging/push_pull.md) | Distributes messages to multiple workers, arranged in a pipeline ||
83-
84-
## Stability Patterns
85-
86-
| Pattern | Description | Status |
87-
|:-------:|:----------- |:------:|
88-
| [Bulkheads](/stability/bulkhead.md) | Enforces a principle of failure containment (i.e. prevents cascading failures) ||
89-
| [Circuit-Breaker](/stability/circuit-breaker.md) | Stops the flow of the requests when requests are likely to fail ||
90-
| [Deadline](/stability/deadline.md) | 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) ||
91-
| [Fail-Fast](/stability/fail_fast.md) | Checks the availability of required resources at the start of a request and fails if the requirements are not satisfied ||
92-
| [Handshaking](/stability/handshaking.md) | Asks a component if it can take any more load, if it can't, the request is declined ||
93-
| [Steady-State](/stability/steady_state.md) | For every service that accumulates a resource, some other service must recycle that resource ||
94-
95-
## Profiling Patterns
96-
97-
| Pattern | Description | Status |
98-
|:-------:|:----------- |:------:|
99-
| [Timing Functions](/profiling/timing.md) | Wraps a function and logs the execution ||
100-
101-
## Idioms
102-
103-
| Pattern | Description | Status |
104-
|:-------:|:----------- |:------:|
105-
| [Functional Options](/idiom/functional-options.md) | Allows creating clean APIs with sane defaults and idiomatic overrides ||
106-
107-
## Anti-Patterns
108-
109-
| Pattern | Description | Status |
110-
|:-------:|:----------- |:------:|
111-
| [Cascading Failures](/anti-patterns/cascading_failures.md) | A failure in a system of interconnected parts in which the failure of a part causes a domino effect ||
1+
<div class="gp-hero">
2+
<img src="gopher.png" alt="Go Gopher" class="gp-hero__gopher">
3+
4+
<h1 class="gp-hero__title">Go Design Patterns</h1>
5+
6+
<p class="gp-hero__subtitle">
7+
A curated collection of <strong>46 idiomatic design &amp; application patterns</strong> for the Go programming language — actively maintained and 100% implemented.
8+
</p>
9+
10+
<div class="gp-stats">
11+
<span class="gp-stat">
12+
<span class="gp-stat__icon">📦</span>
13+
<span class="gp-stat__number">46</span> Patterns
14+
</span>
15+
<span class="gp-stat">
16+
<span class="gp-stat__icon">📂</span>
17+
<span class="gp-stat__number">9</span> Categories
18+
</span>
19+
<span class="gp-stat">
20+
<span class="gp-stat__icon">✅</span>
21+
<span class="gp-stat__number">100%</span> Implemented
22+
</span>
23+
</div>
24+
25+
<div class="gp-cta">
26+
<a href="creational/abstract_factory.html" class="gp-cta__btn gp-cta__btn--primary">
27+
🚀 Start Learning
28+
</a>
29+
<a href="https://github.com/RaikaSurendra/go-design-patterns" class="gp-cta__btn gp-cta__btn--secondary">
30+
⭐ GitHub
31+
</a>
32+
</div>
33+
</div>
34+
35+
<div class="gp-categories">
36+
37+
<a href="creational/abstract_factory.html" class="gp-card">
38+
<div class="gp-card__icon">🏗️</div>
39+
<div class="gp-card__title">Creational</div>
40+
<div class="gp-card__desc">Object creation mechanisms — factories, builders, singletons, and pools.</div>
41+
<div class="gp-card__count">5 patterns</div>
42+
</a>
43+
44+
<a href="structural/bridge.html" class="gp-card">
45+
<div class="gp-card__icon">🧱</div>
46+
<div class="gp-card__title">Structural</div>
47+
<div class="gp-card__desc">Compose objects into larger structures — bridges, proxies, decorators, and facades.</div>
48+
<div class="gp-card__count">6 patterns</div>
49+
</a>
50+
51+
<a href="behavioral/chain_of_responsibility.html" class="gp-card">
52+
<div class="gp-card__icon">🎭</div>
53+
<div class="gp-card__title">Behavioral</div>
54+
<div class="gp-card__desc">Manage algorithms and object responsibilities — commands, observers, and strategies.</div>
55+
<div class="gp-card__count">10 patterns</div>
56+
</a>
57+
58+
<a href="synchronization/condition_variable.html" class="gp-card">
59+
<div class="gp-card__icon">🔒</div>
60+
<div class="gp-card__title">Synchronization</div>
61+
<div class="gp-card__desc">Coordinate concurrent access — mutexes, semaphores, monitors, and condition variables.</div>
62+
<div class="gp-card__count">5 patterns</div>
63+
</a>
64+
65+
<a href="concurrency/barrier.html" class="gp-card">
66+
<div class="gp-card__icon">⚡</div>
67+
<div class="gp-card__title">Concurrency</div>
68+
<div class="gp-card__desc">Harness goroutines and channels — barriers, generators, coroutines, and reactors.</div>
69+
<div class="gp-card__count">8 patterns</div>
70+
</a>
71+
72+
<a href="messaging/fan_in.html" class="gp-card">
73+
<div class="gp-card__icon">📨</div>
74+
<div class="gp-card__title">Messaging</div>
75+
<div class="gp-card__desc">Move data between components — fan-in/out, pub/sub, futures, and push/pull.</div>
76+
<div class="gp-card__count">5 patterns</div>
77+
</a>
78+
79+
<a href="stability/bulkhead.html" class="gp-card">
80+
<div class="gp-card__icon">🛡️</div>
81+
<div class="gp-card__title">Stability</div>
82+
<div class="gp-card__desc">Build resilient systems — circuit breakers, bulkheads, deadlines, and fail-fast.</div>
83+
<div class="gp-card__count">6 patterns</div>
84+
</a>
85+
86+
<a href="profiling/timing.html" class="gp-card">
87+
<div class="gp-card__icon">📊</div>
88+
<div class="gp-card__title">Profiling</div>
89+
<div class="gp-card__desc">Measure and optimize performance with timing functions and profiling wrappers.</div>
90+
<div class="gp-card__count">1 pattern</div>
91+
</a>
92+
93+
<a href="idiom/functional-options.html" class="gp-card">
94+
<div class="gp-card__icon">🔧</div>
95+
<div class="gp-card__title">Idioms</div>
96+
<div class="gp-card__desc">Go-specific idioms — functional options for clean, extensible APIs.</div>
97+
<div class="gp-card__count">1 pattern</div>
98+
</a>
99+
100+
</div>
101+
102+
<hr class="gp-divider">
103+
104+
<div class="gp-footer">
105+
<p>
106+
Actively maintained fork of <a href="https://github.com/tmrts/go-patterns">tmrts/go-patterns</a> — updated with modern Go, complete implementations, and full documentation. Contributions welcome!
107+
</p>
108+
</div>

SUMMARY.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
---
66

7-
# Creational Patterns
7+
# 🏗️ Creational Patterns
88

99
- [Abstract Factory](creational/abstract_factory.md)
1010
- [Builder](creational/builder.md)
1111
- [Factory Method](creational/factory.md)
1212
- [Object Pool](creational/object-pool.md)
1313
- [Singleton](creational/singleton.md)
1414

15-
# Structural Patterns
15+
# 🧱 Structural Patterns
1616

1717
- [Bridge](structural/bridge.md)
1818
- [Composite](structural/composite.md)
@@ -21,7 +21,7 @@
2121
- [Flyweight](structural/flyweight.md)
2222
- [Proxy](structural/proxy.md)
2323

24-
# Behavioral Patterns
24+
# 🎭 Behavioral Patterns
2525

2626
- [Chain of Responsibility](behavioral/chain_of_responsibility.md)
2727
- [Command](behavioral/command.md)
@@ -34,15 +34,15 @@
3434
- [Template](behavioral/template.md)
3535
- [Visitor](behavioral/visitor.md)
3636

37-
# Synchronization Patterns
37+
# 🔒 Synchronization Patterns
3838

3939
- [Condition Variable](synchronization/condition_variable.md)
4040
- [Lock/Mutex](synchronization/mutex.md)
4141
- [Monitor](synchronization/monitor.md)
4242
- [Read-Write Lock](synchronization/read_write_lock.md)
4343
- [Semaphore](synchronization/semaphore.md)
4444

45-
# Concurrency Patterns
45+
# Concurrency Patterns
4646

4747
- [N-Barrier](concurrency/barrier.md)
4848
- [Bounded Parallelism](concurrency/bounded_parallelism.md)
@@ -53,15 +53,15 @@
5353
- [Parallelism](concurrency/parallelism.md)
5454
- [Producer Consumer](concurrency/producer_consumer.md)
5555

56-
# Messaging Patterns
56+
# 📨 Messaging Patterns
5757

5858
- [Fan-In](messaging/fan_in.md)
5959
- [Fan-Out](messaging/fan_out.md)
6060
- [Futures & Promises](messaging/futures_promises.md)
6161
- [Publish/Subscribe](messaging/publish_subscribe.md)
6262
- [Push & Pull](messaging/push_pull.md)
6363

64-
# Stability Patterns
64+
# 🛡️ Stability Patterns
6565

6666
- [Bulkheads](stability/bulkhead.md)
6767
- [Circuit-Breaker](stability/circuit-breaker.md)
@@ -70,15 +70,15 @@
7070
- [Handshaking](stability/handshaking.md)
7171
- [Steady-State](stability/steady_state.md)
7272

73-
# Profiling Patterns
73+
# 📊 Profiling Patterns
7474

7575
- [Timing Functions](profiling/timing.md)
7676

77-
# Idioms
77+
# 🔧 Idioms
7878

7979
- [Functional Options](idiom/functional-options.md)
8080

81-
# Anti-Patterns
81+
# ⚠️ Anti-Patterns
8282

8383
- [Cascading Failures](anti-patterns/cascading_failures.md)
8484

anti-patterns/cascading_failures.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Cascading Failures (Anti-Pattern)
1+
# Cascading Failures (Anti-Pattern) <span class="gp-difficulty gp-difficulty--medium">Medium</span>
22

33
A cascading failure occurs when a failure in one component of an interconnected
44
system triggers failures in dependent components, creating a domino effect that

behavioral/chain_of_responsibility.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Chain of Responsibility Pattern
1+
# Chain of Responsibility Pattern <span class="gp-difficulty gp-difficulty--medium">Medium</span>
22

33
The chain of responsibility pattern avoids coupling the sender of a request to
44
its receiver by giving more than one object a chance to handle the request.

behavioral/command.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Command Pattern
1+
# Command Pattern <span class="gp-difficulty gp-difficulty--easy">Easy</span>
22

33
The command pattern encapsulates a request as an object, allowing you to
44
parameterize clients with different requests, queue or log requests, and

behavioral/mediator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Mediator Pattern
1+
# Mediator Pattern <span class="gp-difficulty gp-difficulty--medium">Medium</span>
22

33
The mediator pattern defines an object that encapsulates how a set of objects
44
interact. It promotes loose coupling by preventing objects from referring to each

behavioral/memento.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Memento Pattern
1+
# Memento Pattern <span class="gp-difficulty gp-difficulty--medium">Medium</span>
22

33
The memento pattern captures and externalizes an object's internal state so that
44
the object can be restored to this state later, without violating encapsulation.

behavioral/observer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Observer Pattern
1+
# Observer Pattern <span class="gp-difficulty gp-difficulty--easy">Easy</span>
22

33
The [observer pattern](https://en.wikipedia.org/wiki/Observer_pattern) allows a type instance to "publish" events to other type instances ("observers") who wish to be updated when a particular event occurs.
44

behavioral/registry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Registry Pattern
1+
# Registry Pattern <span class="gp-difficulty gp-difficulty--easy">Easy</span>
22

33
The registry pattern provides a well-known object that other objects can use to
44
find common objects and services. It acts as a central lookup table where

behavioral/state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# State Pattern
1+
# State Pattern <span class="gp-difficulty gp-difficulty--medium">Medium</span>
22

33
The state pattern allows an object to alter its behavior when its internal state
44
changes. The object appears to change its type. Each state is represented as a

0 commit comments

Comments
 (0)