-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tech stack: Go: add Interfaces
section
#69
base: main
Are you sure you want to change the base?
Conversation
Your Render PR Server URL is https://engineering-handbook-pr-69.onrender.com. Follow its progress at https://dashboard.render.com/static/srv-ccic9e9gp3jjvdiit0f0. |
406f63b
to
4b26694
Compare
5138e41
to
56a8c80
Compare
@qdm12 Might wanna add some go devs in company to review? |
56a8c80
to
4c78eaf
Compare
4c78eaf
to
4f8550c
Compare
|
||
This is also useful such that you can use the narrow interfaces (such as `Getter`) in unexported package-local functions. | ||
|
||
### Exported interfaces with exported methods only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qdm12 could you maybe please elaborate this section even more? Maybe add examples to those 3 paths and some explanation.
And the ideal would be to refer the particular article or a section/post from go.dev.
value := myInterface.(*myImplementation).GetValue() | ||
``` | ||
|
||
Interfaces should have one or two methods. If you need a larger interface, compose it using smaller interfaces. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious about the reasoning for this? specifically that an interface should only have 1 or 2 methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall looks good, just one comment/question
Instead do a type assertion on the interface to call the method. For example: | ||
|
||
```go | ||
value := myInterface.(*myImplementation).GetValue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to assert whether or not myInterface
is of the *myImplementation
value := myInterface.(*myImplementation).GetValue() | |
impl, ok := myInterface.(*myImplementation) | |
assert.True(t, ok) | |
value := impl.GetValue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, since it's a test you know in advance what implementation it is. And if not, panicing in the test is fine I'd say.
|
No description provided.