Compare commits
No commits in common. "feature/YOBB-add-user-country-header" and "main" have entirely different histories.
feature/YO
...
main
@ -1,31 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"yobble-gateway-go/internal/logger"
|
||||
"yobble-gateway-go/pkg/geoip"
|
||||
)
|
||||
|
||||
type CountryMW struct {
|
||||
Geo *geoip.GeoIPService
|
||||
}
|
||||
|
||||
func (m *CountryMW) AddCountryHeaderIPMiddleware(next http.Handler) http.Handler {
|
||||
op := "middleware.AddCountryHeaderIPMiddleware"
|
||||
log := logger.NewLoggerWithOp(op)
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
realIP := GetRealIP(r)
|
||||
log.Debug(op, "realIP", realIP)
|
||||
_, countryCode := m.Geo.IsCountryBlocked(realIP)
|
||||
log.Debug(op, "countryCode", countryCode)
|
||||
|
||||
if countryCode != "" {
|
||||
r.Header.Set("X-Country-Code", countryCode)
|
||||
} else {
|
||||
r.Header.Set("X-Country-Code", "Undefined")
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
@ -31,15 +31,11 @@ func NewServer(cfg *config.Settings, geoIPService *geoip.GeoIPService) *Server {
|
||||
// Create the main proxy handler
|
||||
proxyHandler := proxy.NewProxyHandler(cfg, geoIPService)
|
||||
|
||||
//Initialize country middleware
|
||||
countryMW := &middleware.CountryMW{Geo: geoIPService}
|
||||
// Apply middleware chain
|
||||
chain := middleware.RemoveTrailingSlashMiddleware(
|
||||
middleware.RealIPMiddleware(
|
||||
countryMW.AddCountryHeaderIPMiddleware(
|
||||
proxyHandler,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
addr := fmt.Sprintf("%s:%s", cfg.Server.Host, cfg.Server.Port)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user