From e6c6b4e06f7a23fa36eab125a47bdfcfa55c358a Mon Sep 17 00:00:00 2001 From: TwiN Date: Mon, 11 Apr 2022 01:39:47 -0400 Subject: [PATCH] chore: Update TwiN/health to v1.4.0 --- go.mod | 2 +- go.sum | 4 ++-- vendor/github.com/TwiN/health/LICENSE.md | 2 +- vendor/github.com/TwiN/health/Makefile | 5 ++++- vendor/github.com/TwiN/health/README.md | 13 ++++++++++--- vendor/github.com/TwiN/health/health.go | 23 +++++++++++++++++++++-- vendor/modules.txt | 4 ++-- 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index dcdfdcde..ae14e8e0 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/TwiN/g8 v1.3.0 github.com/TwiN/gocache v1.2.4 github.com/TwiN/gocache/v2 v2.0.0 - github.com/TwiN/health v1.3.0 + github.com/TwiN/health v1.4.0 github.com/coreos/go-oidc/v3 v3.1.0 github.com/go-ping/ping v0.0.0-20210911151512-381826476871 github.com/google/uuid v1.3.0 diff --git a/go.sum b/go.sum index 84b9b3fc..968761ab 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,8 @@ github.com/TwiN/gocache v1.2.4 h1:AfJ1YRcxtQ/zZEN61URDwk/dwFG7LSRenU5qIm9dQzo= github.com/TwiN/gocache v1.2.4/go.mod h1:BjabsQQy6z5uHDorHa4LJVPEzFeitLIDbCtdv3gc1gA= github.com/TwiN/gocache/v2 v2.0.0 h1:CPbDNKdSJpmBkh7aWcO7D3KK1yWaMlwX+3dsBPE8/so= github.com/TwiN/gocache/v2 v2.0.0/go.mod h1:j4MABVaia2Tp53ERWc/3l4YxkswtPjB2hQzmL/kD/VQ= -github.com/TwiN/health v1.3.0 h1:xw90rZqg0NH5MRkVHzlgtDdP+EQd43v3yMqQVtYlGHg= -github.com/TwiN/health v1.3.0/go.mod h1:Bt+lEvSi6C/9NWb7OoGmUmgtS4dfPeMM9EINnURv5dE= +github.com/TwiN/health v1.4.0 h1:Ts7lb4ihYDpVEbFSGAhSEZTSwuDOADnwJLFngFl4xzw= +github.com/TwiN/health v1.4.0/go.mod h1:CSUh+ryfD2POS2vKtc/yO4IxgR58lKvQ0/8qnoPqPqs= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= diff --git a/vendor/github.com/TwiN/health/LICENSE.md b/vendor/github.com/TwiN/health/LICENSE.md index ca64af38..3453cb7b 100644 --- a/vendor/github.com/TwiN/health/LICENSE.md +++ b/vendor/github.com/TwiN/health/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 TwiN +Copyright (c) 2022 TwiN Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/vendor/github.com/TwiN/health/Makefile b/vendor/github.com/TwiN/health/Makefile index 1e0f6f60..f51c74a2 100644 --- a/vendor/github.com/TwiN/health/Makefile +++ b/vendor/github.com/TwiN/health/Makefile @@ -1,2 +1,5 @@ bench: - go test -bench . -race \ No newline at end of file + go test -bench . -race + +test: + go test . -race \ No newline at end of file diff --git a/vendor/github.com/TwiN/health/README.md b/vendor/github.com/TwiN/health/README.md index a22a0274..ff50a1fb 100644 --- a/vendor/github.com/TwiN/health/README.md +++ b/vendor/github.com/TwiN/health/README.md @@ -1,5 +1,5 @@ # health -![build](https://github.com/TwiN/health/workflows/build/badge.svg?branch=master) +![test](https://github.com/TwiN/health/workflows/test/badge.svg?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/TwiN/health)](https://goreportcard.com/report/github.com/TwiN/health) [![codecov](https://codecov.io/gh/TwiN/health/branch/master/graph/badge.svg)](https://codecov.io/gh/TwiN/health) [![Go version](https://img.shields.io/github/go-mod/go-version/TwiN/health.svg)](https://github.com/TwiN/health) @@ -12,7 +12,7 @@ it over and over again. ## Installation -``` +```console go get -u github.com/TwiN/health ``` @@ -37,7 +37,11 @@ The above will cause the response body to become `{"status":"UP"}` and `{"status unless there is a reason, in which case a reason set to `because` would return `{"status":"UP", "reason":"because"}` and `{"status":"DOWN", "reason":"because"}` respectively. -To change the health of the application, you can use `health.SetStatus()` where `` is one `health.Up` +To set the health status to `DOWN`, you may use `health.SetUnhealthy("`)` -- the +string passed will be automatically set as the reason. In a similar fashion, to set the health status to `UP`, +you may use `health.SetHealthy()`. + +Alternatively, to change the health of the application, you can use `health.SetStatus()` where `` is `health.Up` or `health.Down`: ```go health.SetStatus(health.Up) @@ -51,6 +55,9 @@ health.SetReason("database is unreachable") Generally speaking, you'd only want to include a reason if the status is `Down`, but you can do as you desire. +For the sake of convenience, you can also use `health.SetStatusAndReason(, )` instead of doing +`health.SetStatus()` and `health.SetReason()` separately. + ### Complete example ```go diff --git a/vendor/github.com/TwiN/health/health.go b/vendor/github.com/TwiN/health/health.go index bb33379e..527e7bb7 100644 --- a/vendor/github.com/TwiN/health/health.go +++ b/vendor/github.com/TwiN/health/health.go @@ -13,6 +13,7 @@ var ( } ) +// responseBody is the body of the response returned by the health handler. type responseBody struct { Status string `json:"status"` Reason string `json:"reason,omitempty"` @@ -20,8 +21,7 @@ type responseBody struct { // healthHandler is the HTTP handler for serving the health endpoint type healthHandler struct { - useJSON bool - resetReasonOnUp bool + useJSON bool status Status reason string @@ -104,3 +104,22 @@ func SetStatusAndReason(status Status, reason string) { handler.reason = reason handler.mutex.Unlock() } + +// SetHealthy sets the status to Up and the reason to a blank string +func SetHealthy() { + handler.mutex.Lock() + handler.status = Up + handler.reason = "" + handler.mutex.Unlock() +} + +// SetUnhealthy sets the status to Down and the reason to the string passed as parameter +// +// Unlike SetHealthy, this function enforces setting a reason, because it's good practice to give at least a bit +// of information as to why an application is unhealthy, and this library attempts to promote good practices. +func SetUnhealthy(reason string) { + handler.mutex.Lock() + handler.status = Down + handler.reason = reason + handler.mutex.Unlock() +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 78594b4d..165c9480 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -7,8 +7,8 @@ github.com/TwiN/gocache # github.com/TwiN/gocache/v2 v2.0.0 ## explicit; go 1.17 github.com/TwiN/gocache/v2 -# github.com/TwiN/health v1.3.0 -## explicit; go 1.17 +# github.com/TwiN/health v1.4.0 +## explicit; go 1.18 github.com/TwiN/health # github.com/beorn7/perks v1.0.1 ## explicit; go 1.11