This commit is contained in:
Hsy
2025-02-20 17:32:53 +08:00
commit 144c1788f7
57 changed files with 2827 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package middleware
import (
"context"
"hk/pkg/middleware"
"net/http"
)
type RealIPMiddleware struct {
}
func NewRealIPMiddleware() *RealIPMiddleware {
return &RealIPMiddleware{}
}
func (m *RealIPMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ipaddress := middleware.GetRealIP(r)
ctx := context.WithValue(r.Context(), "ip", ipaddress)
next(w, r.WithContext(ctx))
}
}