feat: added API gateway

This commit is contained in:
ITQ
2025-12-17 11:00:50 +03:00
parent daa8c24482
commit 340ae43d22
30 changed files with 2838 additions and 3 deletions
+47
View File
@@ -0,0 +1,47 @@
package middleware
import (
"log"
"net/http"
"time"
)
type responseWriter struct {
http.ResponseWriter
statusCode int
written int64
}
func (rw *responseWriter) WriteHeader(code int) {
rw.statusCode = code
rw.ResponseWriter.WriteHeader(code)
}
func (rw *responseWriter) Write(b []byte) (int, error) {
n, err := rw.ResponseWriter.Write(b)
rw.written += int64(n)
return n, err
}
func LoggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
wrapped := &responseWriter{
ResponseWriter: w,
statusCode: http.StatusOK,
}
next.ServeHTTP(wrapped, r)
duration := time.Since(start)
log.Printf(
"%s %s %d %s %s",
r.Method,
r.RequestURI,
wrapped.statusCode,
duration,
r.RemoteAddr,
)
})
}