4 ms·
The author of that article is also the author of the Goji framework (very nice web framework for Golang): https://goji.io/ https://goji.io/
by scottpiper 12y ago
The author of that article is also the author of the Goji framework (very nice web framework for Golang): https://goji.io/ https://goji.io/
- Sphax 12y agoI was looking for the example proxy around http.ResponseWriter the author talked about which is implemented in Goji, I believe it's this code: https://github.com/zenazn/goji/blob/master/graceful/middleware.go https://github.com/zenazn/goji/blob/master/graceful/middlewa... I understand it fine except this bit right at the end: var _ http.CloseNotifier = &fancyWriter{} var _ http.Flusher = &fancyWriter{} var _ http.Hijacker = &fancyWriter{} var _ io.ReaderFrom = &fancyWriter{} What's the purpose of this ? According to effective go this just silences the unused imports but I don't think there's a need for that here.
- iand 12y agoThey are static assertions that fancyWriter implements all those interfaces. They are compiled away to nothing but provide a kind of test of correctness.
- Sphax 12y agoOh, ok, makes sense. Thank you.
- rakoo 12y agoThe relevant part of Effective Go is here: http://golang.org/doc/effective_go.html#blank_implements http://golang.org/doc/effective_go.html#blank_implements It allows you to make sure fancyWriter implements all those interfaces, so that any future refactoring that breaks compatibility breaks at compile time. You know how Go makes interfaces concordance implicit ? Whatever has a Read() method is a io.Reader without asking for it ? This explicitly tells the compiler (and other developers) the same thing.
- Sphax 12y agoThank you, I read the wrong part of effective Go apparently, didn't see this. It's clear now.