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 }