From c3b14bcf7e4bcfa3843da92f2521625b92a3e319 Mon Sep 17 00:00:00 2001 From: cangui Date: Tue, 15 Jul 2025 17:30:41 +0200 Subject: [PATCH] ping --- internal/route/main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/route/main.go b/internal/route/main.go index dd1f473..3f9223f 100644 --- a/internal/route/main.go +++ b/internal/route/main.go @@ -8,8 +8,8 @@ import ( "app/shelfly/internal/users" "app/shelfly/renders" "encoding/base64" + "encoding/json" "fmt" - "golang.org/x/crypto/bcrypt" "log" "net/http" "os" @@ -17,10 +17,22 @@ import ( "strings" "time" + "golang.org/x/crypto/bcrypt" + "github.com/gorilla/mux" "golang.org/x/net/webdav" "gorm.io/gorm" ) +func PingHandler() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(map[string]string{ + "message": "pong", + "service": "shelfy", + "version": "1.0.0", // optionnel + }) + } +} func checkUserCredentials(db *gorm.DB, email string, password string) bool { var user models.User @@ -68,6 +80,7 @@ func RoutesPublic(r *mux.Router, bd *gorm.DB) { http.StripPrefix("/static/", http.FileServer(http.Dir("./static")))) // Page de login + r.HandleFunc("/api/ping", PingHandler()).Methods("GET") r.HandleFunc("/login", renders.Login) r.HandleFunc("/api/login", login.LoginHandler(bd)).Methods("POST") r.HandleFunc("/apiV2/login", login.LoginHandlerApi(bd)).Methods("POST")