feat: ServerMux to gorilla/mux, time route

This commit is contained in:
2025-11-22 23:25:00 +03:00
parent 51f30b516e
commit 659369c42b
7 changed files with 208 additions and 12 deletions

View File

@@ -0,0 +1,43 @@
// It's just test file. I'll remove it later
package handlers
import (
"encoding/json"
"net/http"
"time"
"git.nwaifu.su/sergey/MyGoServer/internal/apiserver/models"
)
// TimeHandler handles the time endpoint
type TimeHandler struct{}
func NewTimeHandler() *TimeHandler {
return &TimeHandler{}
}
// ServeHTTP implements http.Handler
func (h *TimeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.handleTime(w, r)
}
// @Summary Get server time
// @Description Возвращает текущее серверное время в формате ISO 8601
// @Tags Time
// @Success 200 {object} models.Response "Текущее время сервера"
// @Router /time [get]
func (h *TimeHandler) handleTime(w http.ResponseWriter, r *http.Request) {
// Get current time in UTC
currentTime := time.Now().UTC()
// Create response with time data
response := models.NewSuccessResponse(map[string]interface{}{
"server_time": currentTime.Format(time.RFC3339),
"unix_timestamp": currentTime.Unix(),
"timezone": "UTC",
})
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}