From 7317f32fe44825a4c91991af885b7fe855d02388 Mon Sep 17 00:00:00 2001 From: Achim Rohn Date: Wed, 7 Jan 2026 21:13:35 +0100 Subject: [PATCH] Add GetQueryParam method to HtmxContext --- htmx_route.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/htmx_route.go b/htmx_route.go index 2c35f79..ecb9ec1 100644 --- a/htmx_route.go +++ b/htmx_route.go @@ -38,6 +38,7 @@ type HtmxContext interface { SetAllRoutes(routes []HtmxRoute) GetAllRoutes() []HtmxRoute GetQueryParams() []HtmxPathParam + GetQueryParam(key string, defaultValue ...string) string GetAuthContext() (bool, AuthContext) GetGoContext() context.Context GetRequest() *http.Request @@ -53,6 +54,19 @@ type HtmxContextImpl struct { routes []HtmxRoute } +func (c *HtmxContextImpl) GetQueryParam(key string, defaultValue ...string) string { + queryParams := c.GetQueryParams() + for _, param := range queryParams { + if param.Key == key { + return param.Value + } + } + if len(defaultValue) > 0 { + return defaultValue[0] + } + return "" +} + func (c *HtmxContextImpl) GetResponseWriter() http.ResponseWriter { return c.res }