From 4c6568b874e7c997f99b49fcaaf619782cbe547f Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Mon, 7 Sep 2020 14:31:19 +0300 Subject: [PATCH] minor --- context/context.go | 5 +++++ middleware/accesslog/accesslog.go | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/context/context.go b/context/context.go index 421be940..7e66c9c6 100644 --- a/context/context.go +++ b/context/context.go @@ -2717,6 +2717,11 @@ func (ctx *Context) CompressWriter(enable bool) error { w.Disabled = true case *ResponseRecorder: if enable { + // If it's a recorder which already wraps the compress, exit. + if _, ok := w.ResponseWriter.(*CompressResponseWriter); ok { + return nil + } + // Keep the Recorder as ctx.writer. // Wrap the existing net/http response writer // with the compressed writer and diff --git a/middleware/accesslog/accesslog.go b/middleware/accesslog/accesslog.go index 7182798d..6a89ffee 100644 --- a/middleware/accesslog/accesslog.go +++ b/middleware/accesslog/accesslog.go @@ -114,7 +114,14 @@ func (ac *AccessLog) SetOutput(writers ...io.Writer) *AccessLog { } } - ac.Writer = io.MultiWriter(writers...) + switch len(writers) { + case 0: + case 1: + ac.Writer = writers[0] + default: + ac.Writer = io.MultiWriter(writers...) + } + return ac }