Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use application/json for Content-Type header in health handler #221

Merged
merged 2 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-v1-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-v1-
go-version: "1.20"
- name: tests
run: scripts/cibuild
- name: Generate Foresight test data
run: go test -v -json -coverprofile=coverage.out ./...> ./test-report.json || true
run: go test -v -json -coverprofile=coverage.out ./...> ./test-report.json || true
- name: Analyze Test and/or Coverage Results
uses: runforesight/foresight-test-kit-action@v1
if: success() || failure()
Expand All @@ -43,4 +37,4 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.out
flags: micro
flags: micro
4 changes: 2 additions & 2 deletions health/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Healthy service example (using the [httpie](https://httpie.org/) command line ut
http http://localhost:8083/livez
HTTP/1.1 200 OK
Content-Length: 109
Content-Type: text/plain; charset=utf-8
Content-Type: application/json
Date: Mon, 17 Jan 2022 23:23:12 GMT

{
Expand All @@ -38,7 +38,7 @@ Unhealthy service:
http http://localhost:8083/livez
HTTP/1.1 503 Service Unavailable
Content-Length: 113
Content-Type: text/plain; charset=utf-8
Content-Type: application/json
Date: Mon, 17 Jan 2022 23:23:20 GMT

{
Expand Down
1 change: 1 addition & 0 deletions health/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// response status is 200 if chk.Check() returns a nil error, 503 otherwise.
func Handler(chk Checker) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
h, healthy := chk.Check(r.Context())
b, _ := json.Marshal(h)
if healthy {
Expand Down