From 37bea336cabcaf57636870e2070a87a8e3bc383e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Jan 2023 01:37:24 -0500 Subject: [PATCH] chore(deps): bump github.com/TwiN/health from 1.5.0 to 1.6.0 (#394) Bumps [github.com/TwiN/health](https://github.com/TwiN/health) from 1.5.0 to 1.6.0. - [Release notes](https://github.com/TwiN/health/releases) - [Commits](https://github.com/TwiN/health/compare/v1.5.0...v1.6.0) --- updated-dependencies: - dependency-name: github.com/TwiN/health dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- vendor/github.com/TwiN/health/health.go | 24 ++++++++++++++++++------ vendor/modules.txt | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index bff4d989..18257ab7 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( github.com/TwiN/g8 v1.4.0 github.com/TwiN/gocache/v2 v2.2.0 - github.com/TwiN/health v1.5.0 + github.com/TwiN/health v1.6.0 github.com/TwiN/whois v1.1.0 github.com/coreos/go-oidc/v3 v3.4.0 github.com/go-ping/ping v0.0.0-20210911151512-381826476871 diff --git a/go.sum b/go.sum index d6df16de..ce60393f 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/TwiN/g8 v1.4.0 h1:RUk5xTtxKCdMo0GGSbBVyjtAAfi2nqVbA9E0C4u5Cxo= github.com/TwiN/g8 v1.4.0/go.mod h1:ECyGJsoIb99klUfvVQoS1StgRLte9yvvPigGrHdy284= github.com/TwiN/gocache/v2 v2.2.0 h1:M3B36KyH24BntxLrLaUb2kgTdq8DzCnfod0IekLG57w= github.com/TwiN/gocache/v2 v2.2.0/go.mod h1:SnUuBsrwGQeNcDG6vhkOMJnqErZM0JGjgIkuKryokYA= -github.com/TwiN/health v1.5.0 h1:ETTtbQfUbiiIiVTSpAiNzesHQvm8qarV/8ctlZsVhwA= -github.com/TwiN/health v1.5.0/go.mod h1:Z6TszwQPMvtSiVx1QMidVRgvVr4KZGfiwqcD7/Z+3iw= +github.com/TwiN/health v1.6.0 h1:L2ks575JhRgQqWWOfKjw9B0ec172hx7GdToqkYUycQM= +github.com/TwiN/health v1.6.0/go.mod h1:Z6TszwQPMvtSiVx1QMidVRgvVr4KZGfiwqcD7/Z+3iw= github.com/TwiN/whois v1.1.0 h1:lhyrC/9yIXntEnbJ+0IBy9Z5NBcreieYyamlvniwq88= github.com/TwiN/whois v1.1.0/go.mod h1:9WbCzYlR+r5eq9vbgJVh7A4H2uR2ct4wKEB0/QITJ/c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/vendor/github.com/TwiN/health/health.go b/vendor/github.com/TwiN/health/health.go index 23964483..56f251e4 100644 --- a/vendor/github.com/TwiN/health/health.go +++ b/vendor/github.com/TwiN/health/health.go @@ -39,10 +39,24 @@ func (h *healthHandler) WithJSON(v bool) *healthHandler { // ServeHTTP serves the HTTP request for the health handler func (h *healthHandler) ServeHTTP(writer http.ResponseWriter, _ *http.Request) { - var statusCode int - var body []byte + statusCode, body, useJSON := h.getResponseStatusCodeAndBodyAndWhetherBodyUsesJSON() + if useJSON { + writer.Header().Set("Content-Type", "application/json") + } + writer.WriteHeader(statusCode) + _, _ = writer.Write(body) +} + +func (h *healthHandler) GetResponseStatusCodeAndBody() (statusCode int, body []byte) { + statusCode, body, _ = h.getResponseStatusCodeAndBodyAndWhetherBodyUsesJSON() + return statusCode, body +} + +func (h *healthHandler) getResponseStatusCodeAndBodyAndWhetherBodyUsesJSON() (statusCode int, body []byte, useJSON bool) { + var status Status + var reason string h.mutex.RLock() - status, reason, useJSON := h.status, h.reason, h.useJSON + status, reason, useJSON = h.status, h.reason, h.useJSON h.mutex.RUnlock() if status == Up { statusCode = http.StatusOK @@ -52,7 +66,6 @@ func (h *healthHandler) ServeHTTP(writer http.ResponseWriter, _ *http.Request) { if useJSON { // We can safely ignore the error here because we know that both values are strings, therefore are supported encoders. body, _ = json.Marshal(responseBody{Status: string(status), Reason: reason}) - writer.Header().Set("Content-Type", "application/json") } else { if len(reason) == 0 { body = []byte(status) @@ -60,8 +73,7 @@ func (h *healthHandler) ServeHTTP(writer http.ResponseWriter, _ *http.Request) { body = []byte(string(status) + ": " + reason) } } - writer.WriteHeader(statusCode) - _, _ = writer.Write(body) + return } // Handler retrieves the health handler diff --git a/vendor/modules.txt b/vendor/modules.txt index 050c437f..fd1fa1b1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -4,7 +4,7 @@ github.com/TwiN/g8 # github.com/TwiN/gocache/v2 v2.2.0 ## explicit; go 1.19 github.com/TwiN/gocache/v2 -# github.com/TwiN/health v1.5.0 +# github.com/TwiN/health v1.6.0 ## explicit; go 1.19 github.com/TwiN/health # github.com/TwiN/whois v1.1.0