Skip to content

Commit

Permalink
Use application/json for Content-Type header in health handler (#221)
Browse files Browse the repository at this point in the history
* Use application/json for Content-Type header in health handler

* Remove actions/cache usage since actions/setup-go@v4 already caches by default
  • Loading branch information
douglaswth committed Apr 28, 2023
1 parent 4aafcf6 commit 931027d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
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

0 comments on commit 931027d

Please sign in to comment.