Add GetQueryParam method to HtmxContext
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user