For details, see Common Anti-Patterns in Go Web Applications.
Strong coupling makes your Web App hard to maintain over time.
The first example shows a tightly coupled service, and the following three a few tactics to approach loose coupling.
All examples cover the same domain and work in the same way.
- Tightly Coupled
- Loosely Coupled
- Loosely Coupled with Code Generation
- Loosely Coupled with Application Layer
The tests
directory holds end-to-end tests for all examples. All applications work the same and expose the same API.
The docker-compose definition holds all services and their dependencies. Run it with:
docker-compose up
Then, run end-to-end tests for all examples at once:
make test
Language | files | blank | comment | code |
---|---|---|---|---|
Go | 4 | 60 | 0 | 292 |
SQL | 1 | 0 | 0 | 1 |
-------- | -------- | -------- | -------- | -------- |
SUM: | 5 | 60 | 0 | 293 |
Language | files | blank | comment | code |
---|---|---|---|---|
Go | 3 | 72 | 0 | 345 |
SQL | 1 | 0 | 0 | 1 |
-------- | -------- | -------- | -------- | -------- |
SUM: | 4 | 72 | 0 | 346 |
Language | files | blank | comment | code |
---|---|---|---|---|
Go | 11 | 549 | 175 | 2452 |
YAML | 1 | 7 | 0 | 124 |
SQL | 1 | 2 | 0 | 21 |
TOML | 1 | 0 | 0 | 5 |
-------- | -------- | -------- | -------- | -------- |
SUM: | 14 | 558 | 175 | 2602 |
Language | files | blank | comment | code |
---|---|---|---|---|
Go | 12 | 575 | 181 | 2562 |
YAML | 1 | 7 | 0 | 124 |
SQL | 1 | 2 | 0 | 21 |
TOML | 1 | 0 | 0 | 5 |
-------- | -------- | -------- | -------- | -------- |
SUM: | 15 | 584 | 181 | 2712 |