Metadata
- Author: Clace
- Full Title: Go Composition Does Not Compose Well With Implicit Interfaces
- Category:#articles
- Document Note: Учитывать описанную проблему при использовании композиции типов.
- Document Tags: go Outline
- Summary: Clace encountered a problem where Server-Sent Events (SSE) stopped working due to a change in how HTTP response status codes were tracked. This issue arose because adding a composition over
http.ResponseWriter
caused it to lose support for the implicit interfacehttp.Flusher
, which is needed for SSE. To fix the problem, the custom struct must explicitly implement thehttp.Flusher
interface to maintain its functionality. - URL: https://clace.io/blog/go-composition/
Highlights
-
The reason for the issue encountered is an implicit interface http.Flusher implemented by most implementations of http.ResponseWriter. Adding a composition over
http.ResponseWriter
causes this implicit interface to no longer be implemented. (View Highlight) -
The takeaway is that if using composition over types which could have implicit interfaces, it is important to look at whether any of those implicit interfaces have to be explicitly implemented by the composing type. (View Highlight)
📂 Articles | Последнее изменение: 21.01.2025 10:44