From d02645bb33559096e97e883ecc1bbc53d29218b3 Mon Sep 17 00:00:00 2001 From: KinjiKawaguchi Date: Sat, 23 Mar 2024 16:31:18 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=E3=83=98=E3=83=AB=E3=82=B9?= =?UTF-8?q?=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E9=96=A2=E9=80=A3=E3=81=AE?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E3=81=AE=E4=BD=8D=E7=BD=AE=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typing-server/api/controller/system/health.go | 20 ------------------- typing-server/api/handler/health.go | 14 +++++++++++++ typing-server/api/router/router.go | 3 +-- 3 files changed, 15 insertions(+), 22 deletions(-) delete mode 100644 typing-server/api/controller/system/health.go create mode 100644 typing-server/api/handler/health.go diff --git a/typing-server/api/controller/system/health.go b/typing-server/api/controller/system/health.go deleted file mode 100644 index 937ac73..0000000 --- a/typing-server/api/controller/system/health.go +++ /dev/null @@ -1,20 +0,0 @@ -package system - -import ( - "log/slog" - "net/http" -) - -// HealthCheck はヘルスチェックのためのハンドラー関数です。 -func HealthCheck(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - _, err := w.Write([]byte("API is running")) - if err != nil { - // エラーログを記録し、処理を終了します。 - // 実際には、この時点でレスポンスヘッダーやボディがクライアントに送信されている可能性が高いため、 - // http.Errorを呼び出すことは推奨されません。 - // 代わりに、ログに記録するなどのサーバー側での対応が適切です。 - slog.Error("failed to write response: %v", err) - } -} - diff --git a/typing-server/api/handler/health.go b/typing-server/api/handler/health.go new file mode 100644 index 0000000..357ddc2 --- /dev/null +++ b/typing-server/api/handler/health.go @@ -0,0 +1,14 @@ +package handler + +import ( + "log/slog" + "net/http" +) + +func HealthCheck(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + _, err := w.Write([]byte("API is running")) + if err != nil { + slog.Error("failed to write response: %v", err) + } +} diff --git a/typing-server/api/router/router.go b/typing-server/api/router/router.go index 2f213cd..c44dee9 100644 --- a/typing-server/api/router/router.go +++ b/typing-server/api/router/router.go @@ -4,14 +4,13 @@ import ( "net/http" "github.com/go-chi/chi/v5" - "github.com/su-its/typing/typing-server/api/controller/system" "github.com/su-its/typing/typing-server/api/handler" ) func SetupRouter() http.Handler { r := chi.NewRouter() - r.Get("/health", system.HealthCheck) + r.Get("/health", handler.HealthCheck) r.Get("/users", handler.GetUsers)