-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Leonardo Schettini
committed
Apr 17, 2021
1 parent
962a9b2
commit 9ba0578
Showing
4 changed files
with
48 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mux | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
|
||
"github.com/leoschet/gaivota" | ||
) | ||
|
||
type HealthCheck struct { | ||
logger *log.Logger | ||
dependencies []gaivota.HealthChecker | ||
} | ||
|
||
func NewHealthCheck(logger *log.Logger, dependencies []gaivota.HealthChecker) *HealthCheck { | ||
return &HealthCheck{ | ||
logger, | ||
dependencies, | ||
} | ||
} | ||
|
||
func (hc *HealthCheck) ServeHTTP(rw http.ResponseWriter, req *http.Request) { | ||
for _, dep := range hc.dependencies { | ||
msg, err := dep.Ping() | ||
if err != nil { | ||
rw.WriteHeader(http.StatusInternalServerError) | ||
rw.Write([]byte(msg)) | ||
return | ||
} | ||
} | ||
|
||
rw.WriteHeader(http.StatusOK) | ||
rw.Write([]byte("pong")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters