mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 00:40:00 +08:00
simplify code with http.Flusher type conversion (#325)
* simplify code with http.Flusher type conversion * simplify code with http.Flusher type conversion, better version
This commit is contained in:
@@ -7,6 +7,12 @@ type WithCodeResponseWriter struct {
|
||||
Code int
|
||||
}
|
||||
|
||||
func (w *WithCodeResponseWriter) Flush() {
|
||||
if flusher, ok := w.Writer.(http.Flusher); ok {
|
||||
flusher.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WithCodeResponseWriter) Header() http.Header {
|
||||
return w.Writer.Header()
|
||||
}
|
||||
@@ -19,9 +25,3 @@ func (w *WithCodeResponseWriter) WriteHeader(code int) {
|
||||
w.Writer.WriteHeader(code)
|
||||
w.Code = code
|
||||
}
|
||||
|
||||
func (w *WithCodeResponseWriter) Flush() {
|
||||
if flusher, ok := w.Writer.(http.Flusher); ok {
|
||||
flusher.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestWithCodeResponseWriter(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
|
||||
flusher, ok := http.ResponseWriter(cw).(http.Flusher)
|
||||
assert.Equal(t, ok, true)
|
||||
assert.True(t, ok)
|
||||
flusher.Flush()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user