From 48c4d1af44349358826d63bb9e9985aa30915533 Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Mon, 20 May 2024 09:43:41 -0700 Subject: [PATCH] feat: add request remote address to context --- adapters/humabunrouter/humabunrouter.go | 8 ++++++++ adapters/humachi/humachi.go | 4 ++++ adapters/humaecho/humaecho.go | 4 ++++ adapters/humafiber/humafiber.go | 4 ++++ adapters/humaflow/humaflow.go | 4 ++++ adapters/humagin/humagin.go | 4 ++++ adapters/humago/humago.go | 4 ++++ adapters/humahttprouter/humahttprouter.go | 4 ++++ adapters/humamux/humamux.go | 4 ++++ api.go | 3 +++ 10 files changed, 43 insertions(+) diff --git a/adapters/humabunrouter/humabunrouter.go b/adapters/humabunrouter/humabunrouter.go index 0887535c..6790b861 100644 --- a/adapters/humabunrouter/humabunrouter.go +++ b/adapters/humabunrouter/humabunrouter.go @@ -45,6 +45,10 @@ func (c *bunContext) Host() string { return c.r.Host } +func (c *bunContext) RemoteAddr() string { + return c.r.RemoteAddr +} + func (c *bunContext) URL() url.URL { return *c.r.URL } @@ -131,6 +135,10 @@ func (c *bunCompatContext) Host() string { return c.r.Host } +func (c *bunCompatContext) RemoteAddr() string { + return c.r.RemoteAddr +} + func (c *bunCompatContext) URL() url.URL { return *c.r.URL } diff --git a/adapters/humachi/humachi.go b/adapters/humachi/humachi.go index e02ec5e2..ba8a551a 100644 --- a/adapters/humachi/humachi.go +++ b/adapters/humachi/humachi.go @@ -43,6 +43,10 @@ func (c *chiContext) Host() string { return c.r.Host } +func (c *chiContext) RemoteAddr() string { + return c.r.RemoteAddr +} + func (c *chiContext) URL() url.URL { return *c.r.URL } diff --git a/adapters/humaecho/humaecho.go b/adapters/humaecho/humaecho.go index c956add1..c183f3ba 100644 --- a/adapters/humaecho/humaecho.go +++ b/adapters/humaecho/humaecho.go @@ -42,6 +42,10 @@ func (c *echoCtx) Host() string { return c.orig.Request().Host } +func (c *echoCtx) RemoteAddr() string { + return c.orig.Request().RemoteAddr +} + func (c *echoCtx) URL() url.URL { return *c.orig.Request().URL } diff --git a/adapters/humafiber/humafiber.go b/adapters/humafiber/humafiber.go index b4e6d8d2..85e81f35 100644 --- a/adapters/humafiber/humafiber.go +++ b/adapters/humafiber/humafiber.go @@ -43,6 +43,10 @@ func (c *fiberCtx) Host() string { return c.orig.Hostname() } +func (c *fiberCtx) RemoteAddr() string { + return c.orig.Context().RemoteAddr().String() +} + func (c *fiberCtx) URL() url.URL { u, _ := url.Parse(string(c.orig.Request().RequestURI())) return *u diff --git a/adapters/humaflow/humaflow.go b/adapters/humaflow/humaflow.go index 4ee29a44..fcea34e8 100644 --- a/adapters/humaflow/humaflow.go +++ b/adapters/humaflow/humaflow.go @@ -41,6 +41,10 @@ func (c *goContext) Host() string { return c.r.Host } +func (c *goContext) RemoteAddr() string { + return c.r.RemoteAddr +} + func (c *goContext) URL() url.URL { return *c.r.URL } diff --git a/adapters/humagin/humagin.go b/adapters/humagin/humagin.go index 992ebf68..ef437866 100644 --- a/adapters/humagin/humagin.go +++ b/adapters/humagin/humagin.go @@ -42,6 +42,10 @@ func (c *ginCtx) Host() string { return c.orig.Request.Host } +func (c *ginCtx) RemoteAddr() string { + return c.orig.Request.RemoteAddr +} + func (c *ginCtx) URL() url.URL { return *c.orig.Request.URL } diff --git a/adapters/humago/humago.go b/adapters/humago/humago.go index 5fa7d7bb..07c63b29 100644 --- a/adapters/humago/humago.go +++ b/adapters/humago/humago.go @@ -43,6 +43,10 @@ func (c *goContext) Host() string { return c.r.Host } +func (c *goContext) RemoteAddr() string { + return c.r.RemoteAddr +} + func (c *goContext) URL() url.URL { return *c.r.URL } diff --git a/adapters/humahttprouter/humahttprouter.go b/adapters/humahttprouter/humahttprouter.go index 6b99a8e7..b464e222 100644 --- a/adapters/humahttprouter/humahttprouter.go +++ b/adapters/humahttprouter/humahttprouter.go @@ -45,6 +45,10 @@ func (c *httprouterContext) Host() string { return c.r.Host } +func (c *httprouterContext) RemoteAddr() string { + return c.r.RemoteAddr +} + func (c *httprouterContext) URL() url.URL { return *c.r.URL } diff --git a/adapters/humamux/humamux.go b/adapters/humamux/humamux.go index 108b61a0..1f2654a5 100644 --- a/adapters/humamux/humamux.go +++ b/adapters/humamux/humamux.go @@ -43,6 +43,10 @@ func (c *gmuxContext) Host() string { return c.r.Host } +func (c *gmuxContext) RemoteAddr() string { + return c.r.RemoteAddr +} + func (c *gmuxContext) URL() url.URL { return *c.r.URL } diff --git a/api.go b/api.go index 19ac3bf2..60ac05e0 100644 --- a/api.go +++ b/api.go @@ -72,6 +72,9 @@ type Context interface { // Host returns the HTTP host for the request. Host() string + // RemoteAddr returns the remote address of the client. + RemoteAddr() string + // URL returns the full URL for the request. URL() url.URL