♻️ Updated health route

This commit is contained in:
Maxim Lebedev 2021-12-29 04:08:50 +05:00
parent 7c260b0f63
commit 945f0b47dd
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
2 changed files with 6 additions and 8 deletions

View File

@ -10,14 +10,14 @@ import (
type RequestHandler struct{} type RequestHandler struct{}
func NewRequestHandler() *RequestHandler { func NewRequestHandler() *RequestHandler {
return new(RequestHandler) return &RequestHandler{}
} }
func (h *RequestHandler) Register(r *router.Router) { func (h *RequestHandler) Register(r *router.Router) {
r.GET("/health", h.RequestHandler) r.GET("/health", h.read)
} }
func (h *RequestHandler) RequestHandler(ctx *http.RequestCtx) { func (h *RequestHandler) read(ctx *http.RequestCtx) {
ctx.SetContentType(common.MIMETextPlainCharsetUTF8) ctx.SetContentType(common.MIMETextPlainCharsetUTF8)
ctx.SetStatusCode(http.StatusOK) ctx.SetStatusCode(http.StatusOK)
} }

View File

@ -9,7 +9,7 @@ import (
http "github.com/valyala/fasthttp" http "github.com/valyala/fasthttp"
delivery "source.toby3d.me/website/oauth/internal/health/delivery/http" delivery "source.toby3d.me/website/oauth/internal/health/delivery/http"
"source.toby3d.me/website/oauth/internal/util" "source.toby3d.me/website/oauth/internal/testing/httptest"
) )
func TestRequestHandler(t *testing.T) { func TestRequestHandler(t *testing.T) {
@ -18,13 +18,11 @@ func TestRequestHandler(t *testing.T) {
r := router.New() r := router.New()
delivery.NewRequestHandler().Register(r) delivery.NewRequestHandler().Register(r)
client, _, cleanup := util.TestServe(t, r.Handler) client, _, cleanup := httptest.New(t, r.Handler)
t.Cleanup(cleanup) t.Cleanup(cleanup)
req := http.AcquireRequest() req := httptest.NewRequest(http.MethodGet, "https://app.example.com/health", nil)
defer http.ReleaseRequest(req) defer http.ReleaseRequest(req)
req.Header.SetMethod(http.MethodGet)
req.SetRequestURI("https://app.example.com/health")
resp := http.AcquireResponse() resp := http.AcquireResponse()
defer http.ReleaseResponse(resp) defer http.ReleaseResponse(resp)