From 72838a5d2ed526349dc563eb16879ecab8e18ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Flc=E3=82=9B?= Date: Wed, 26 Apr 2023 22:37:48 +0800 Subject: [PATCH] fix: golanglint --- context.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/context.go b/context.go index 5716318e..289cef12 100644 --- a/context.go +++ b/context.go @@ -665,7 +665,7 @@ func (c *Context) BindHeader(obj any) error { // It will abort the request with HTTP 400 if any error occurs. func (c *Context) BindUri(obj any) error { if err := c.ShouldBindUri(obj); err != nil { - c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind) //nolint: errcheck + c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind) // nolint: errcheck return err } return nil @@ -676,7 +676,7 @@ func (c *Context) BindUri(obj any) error { // See the binding package. func (c *Context) MustBindWith(obj any, b binding.Binding) error { if err := c.ShouldBindWith(obj, b); err != nil { - c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind) //nolint: errcheck + c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind) // nolint: errcheck return err } return nil @@ -1075,6 +1075,9 @@ func (c *Context) SSEvent(name string, message any) { // indicates "Is client disconnected in middle of stream" func (c *Context) Stream(step func(w io.Writer) bool) bool { w := c.Writer + if _, ok := w.(http.CloseNotifier); !ok { + return false + } clientGone := w.CloseNotify() for { select { @@ -1082,7 +1085,9 @@ func (c *Context) Stream(step func(w io.Writer) bool) bool { return true default: keepOpen := step(w) - w.Flush() + if flusher, ok := w.(http.Flusher); ok { + flusher.Flush() + } if !keepOpen { return false } @@ -1130,7 +1135,7 @@ func (c *Context) Negotiate(code int, config Negotiate) { c.TOML(code, data) default: - c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server")) //nolint: errcheck + c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server")) // nolint: errcheck } }