feat: removed default handler
This commit is contained in:
@@ -1,55 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log/slog"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/robindittmar/dttmr-api/internal/api/response"
|
|
||||||
)
|
|
||||||
|
|
||||||
type apiResponse struct {
|
|
||||||
Method string `json:"method"`
|
|
||||||
Url string `json:"url"`
|
|
||||||
Proto string `json:"proto"`
|
|
||||||
Header map[string]string `json:"header"`
|
|
||||||
Host string `json:"host"`
|
|
||||||
RemoteAddr string `json:"remoteAddr"`
|
|
||||||
Form map[string]string `json:"form"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultHandler handles the default route
|
|
||||||
//
|
|
||||||
// @Summary Default route handler
|
|
||||||
// @Description Default route handler
|
|
||||||
// @Tags
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Success 200 {object} apiResponse
|
|
||||||
// @Router / [get]
|
|
||||||
func DefaultHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
ctx := r.Context()
|
|
||||||
|
|
||||||
resp := apiResponse{
|
|
||||||
Method: r.Method,
|
|
||||||
Url: r.URL.String(),
|
|
||||||
Proto: r.Proto,
|
|
||||||
Header: make(map[string]string),
|
|
||||||
Host: r.Host,
|
|
||||||
RemoteAddr: r.RemoteAddr,
|
|
||||||
Form: make(map[string]string),
|
|
||||||
}
|
|
||||||
|
|
||||||
for k, v := range r.Header {
|
|
||||||
resp.Header[k] = v[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := r.ParseForm(); err == nil {
|
|
||||||
for k, v := range r.Form {
|
|
||||||
resp.Form[k] = v[0]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
slog.ErrorContext(ctx, "error parsing form", slog.Any("error", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
response.JSON(ctx, w, http.StatusOK, resp)
|
|
||||||
}
|
|
||||||
@@ -35,7 +35,6 @@ func NewMux(cfg Config) http.Handler {
|
|||||||
protected := middleware.WithJWT(authService)
|
protected := middleware.WithJWT(authService)
|
||||||
|
|
||||||
apiMux := http.NewServeMux()
|
apiMux := http.NewServeMux()
|
||||||
apiMux.HandleFunc("/", handler.DefaultHandler)
|
|
||||||
apiMux.HandleFunc("GET /health", handler.HealthHandler)
|
apiMux.HandleFunc("GET /health", handler.HealthHandler)
|
||||||
|
|
||||||
// Auth
|
// Auth
|
||||||
|
|||||||
Reference in New Issue
Block a user