init
This commit is contained in:
22
service/api/internal/middleware/realipmiddleware.go
Normal file
22
service/api/internal/middleware/realipmiddleware.go
Normal 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))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user