From 8ff437cef807453e3e0474af4b8f107b08173624 Mon Sep 17 00:00:00 2001 From: Tibz-Dankan Date: Wed, 14 Aug 2024 20:14:37 +0300 Subject: [PATCH] fix: implement a custom method 'Flush()' for the responseWriter to resolve the error 'Response writer does not implement http.Flusher' --- internal/middlewares/requestDuration.go | 6 ++++++ internal/routes/request/makeRequest.go | 1 - internal/services/date.go | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/middlewares/requestDuration.go b/internal/middlewares/requestDuration.go index 6bf4d1a..0cc6cbd 100644 --- a/internal/middlewares/requestDuration.go +++ b/internal/middlewares/requestDuration.go @@ -51,3 +51,9 @@ func (rw *responseWriter) WriteHeader(code int) { rw.statusCode = code rw.ResponseWriter.WriteHeader(code) } + +func (rw *responseWriter) Flush() { + if flusher, ok := rw.ResponseWriter.(http.Flusher); ok { + flusher.Flush() + } +} diff --git a/internal/routes/request/makeRequest.go b/internal/routes/request/makeRequest.go index 3dd0c49..f732949 100644 --- a/internal/routes/request/makeRequest.go +++ b/internal/routes/request/makeRequest.go @@ -167,7 +167,6 @@ func validateApp(app models.App) (bool, error) { endTime, _ := appDateEnd.HourMinSecTime() currentTimeStart, _ := appDateStart.CurrentTime() currentTimeEnd, _ := appDateEnd.CurrentTime() - // log.Printf("app:%s rs:%s startTime:%s re:%s endTime: %s\n", app.Name, rt.Start, startTime, rt.End, endTime) isEqualToStartTime := currentTimeStart.Equal(startTime) isEqualToEndTime := currentTimeEnd.Equal(endTime) diff --git a/internal/services/date.go b/internal/services/date.go index 86fdd9a..9991954 100644 --- a/internal/services/date.go +++ b/internal/services/date.go @@ -61,6 +61,7 @@ func (d *Date) ISOTime() (time.Time, error) { // Return the date string in the format // "2006-01-02 15:04:05.999999999 -0700 MST" +// in the provided timezone func (d *Date) hourMinSecStr() string { currentTime, _ := d.CurrentTime()