Add GetQueryParam method to HtmxContext

This commit is contained in:
Achim Rohn
2026-01-07 21:13:35 +01:00
parent 72917b7db1
commit 7317f32fe4
+14
View File
@@ -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
}