https://github.com/karantan/go-interfaces
Examples of accepting interfaces and returning structs
https://github.com/karantan/go-interfaces
Last synced: 2 months ago
JSON representation
Examples of accepting interfaces and returning structs
- Host: GitHub
- URL: https://github.com/karantan/go-interfaces
- Owner: karantan
- License: bsd-3-clause
- Created: 2021-09-21T11:54:40.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-26T16:14:07.000Z (over 3 years ago)
- Last Synced: 2025-03-17T02:11:19.310Z (2 months ago)
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Interfaces 
When I started writing tests in Go, I sometimes used interfaces to mock
things in tests. Then I discovered that this is not the correct way:- [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments#interfaces)
- [SOLID Go Design](https://dave.cheney.net/2016/08/20/solid-go-design)
- [Accept Interfaces Return Struct in Go](https://mycodesmells.com/post/accept-interfaces-return-struct-in-go)Similar to [github.com:karantan/go-concurrency](https://github.com/karantan/go-concurrency),
I decided to create (another) "lessons learned/good practices" repo that shows how to
accepting interfaces and returning structs in practice._Preemptive abstractions make systems complex._
I won't explain in detail why it's a bad practice to return interfaces because it's
already been explained in the posts linked above. Please read them before going
through the code here.Additional resources:
- [Learn Go with test-driven development](https://github.com/quii/learn-go-with-tests)
- [Writing Good Unit Tests; Don’t Mock Database Connections](https://qvault.io/clean-code/writing-good-unit-tests-dont-mock-database-connections/)