Hey, I’m currently learning Go and building a REST API, but I’m getting confused about implicit interface satisfaction. I kind of understand the basic idea, that a type implements an interface just by having the required methods, but when I see it used in different places in a real project, I get lost.
I’m following a tutorial to learn what to use, when, and how. But the instructor sometimes manipulates the request and response variables by wrapping them in custom structs and things like that. For example, creating a custom responseWriter struct that embeds http.ResponseWriter and overrides WriteHeader to capture the status code.
Not limited to this, but I am looking for a general understanding of this topic, as I believe this is the topic that is holding me from getting a better knowledge of go.
I don’t fully understand when and why this pattern is used, and how to recognize it quickly when reading a codebase. It makes it hard for me to follow what’s going on.
I attached a small example below. Can someone explain in simple terms what’s happening here, why it’s done this way, and how I should think about implicit interfaces when building REST APIs in Go?
I am open to reading article/ referring a book/ watching a tutorial, any which gives me an in-depth understanding of what to use when and how in Implicit Interface Satisfaction.