diff --git a/main.go b/main.go index 625f27600..de6e3cc52 100644 --- a/main.go +++ b/main.go @@ -195,6 +195,7 @@ func main() { } r.Map("", &handler.HomeHandler{}) + r.Map("_status:healthz", injector.Inject(&handler.HealthzHandler{})) r.Map("auth:signup", injector.Inject(&handler.SignupHandler{})) r.Map("auth:login", injector.Inject(&handler.LoginHandler{})) diff --git a/pkg/server/handler/healthz.go b/pkg/server/handler/healthz.go new file mode 100644 index 000000000..2ddfbe245 --- /dev/null +++ b/pkg/server/handler/healthz.go @@ -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 +} diff --git a/pkg/server/handler/healthz_test.go b/pkg/server/handler/healthz_test.go new file mode 100644 index 000000000..4ab800329 --- /dev/null +++ b/pkg/server/handler/healthz_test.go @@ -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") + }) +}