This repository has been archived by the owner on Dec 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The healthz endpoint checks if the server is ready to serve request. This endpoint can be used by cloud deployment or self-hosted installations to check the status of the server. refs #264
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 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 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,47 @@ | ||
// Copyright 2015-present Oursky Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package handler | ||
|
||
import ( | ||
"github.com/skygeario/skygear-server/pkg/server/router" | ||
) | ||
|
||
type healthStatusResponse struct { | ||
Status string `json:"status,omitempty"` | ||
} | ||
|
||
type HealthzHandler struct { | ||
PluginReady router.Processor `preprocessor:"plugin_ready"` | ||
preprocessors []router.Processor | ||
} | ||
|
||
func (h *HealthzHandler) Setup() { | ||
h.preprocessors = []router.Processor{ | ||
h.PluginReady, | ||
} | ||
} | ||
|
||
func (h *HealthzHandler) GetPreprocessors() []router.Processor { | ||
return h.preprocessors | ||
} | ||
|
||
func (h *HealthzHandler) Handle(playload *router.Payload, response *router.Response) { | ||
var ( | ||
rep healthStatusResponse | ||
) | ||
rep.Status = "OK" | ||
response.Result = rep | ||
return | ||
} |
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,35 @@ | ||
// Copyright 2015-present Oursky Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package handler | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/skygeario/skygear-server/pkg/server/router" | ||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestHealthzHandler(t *testing.T) { | ||
Convey("HealthzHandler", t, func() { | ||
req := router.Payload{} | ||
resp := router.Response{} | ||
|
||
handler := &HealthzHandler{} | ||
handler.Handle(&req, &resp) | ||
So(resp.Result, ShouldHaveSameTypeAs, healthStatusResponse{}) | ||
s := resp.Result.(healthStatusResponse) | ||
So(s.Status, ShouldEqual, "OK") | ||
}) | ||
} |