aboutsummaryrefslogtreecommitdiffstats
path: root/services/context
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-03-16 20:07:56 +0800
committerGitHub <noreply@github.com>2024-03-16 12:07:56 +0000
commita8893816647140526055acc1c4cfe2d130ce7c47 (patch)
tree3133d65af67bf82843ac8ee7233b06ff5b2c0656 /services/context
parent66902d89e567ab1ae6dfb828636999c61ff0149e (diff)
downloadgitea-a8893816647140526055acc1c4cfe2d130ce7c47.tar.gz
gitea-a8893816647140526055acc1c4cfe2d130ce7c47.zip
Remove AddParamIfExist(AddParam) (#29841)
Follow #29834 Remove AddParamIfExist, use "AddParamString" instead, it should clearly know what is being added into the parameters.
Diffstat (limited to 'services/context')
-rw-r--r--services/context/pagination.go22
1 files changed, 9 insertions, 13 deletions
diff --git a/services/context/pagination.go b/services/context/pagination.go
index 11d37283c9..fb2ef699ce 100644
--- a/services/context/pagination.go
+++ b/services/context/pagination.go
@@ -26,16 +26,6 @@ func NewPagination(total, pagingNum, current, numPages int) *Pagination {
return p
}
-// AddParamIfExist adds a value to the query parameters if the value is not nil
-func (p *Pagination) AddParamIfExist(key string, val any) {
- if val == nil {
- return
- }
- paramData := fmt.Sprint(val)
- urlParam := fmt.Sprintf("%s=%v", url.QueryEscape(key), url.QueryEscape(paramData))
- p.urlParams = append(p.urlParams, urlParam)
-}
-
// AddParamString adds a string parameter directly
func (p *Pagination) AddParamString(key, value string) {
urlParam := fmt.Sprintf("%s=%v", url.QueryEscape(key), url.QueryEscape(value))
@@ -49,8 +39,14 @@ func (p *Pagination) GetParams() template.URL {
// SetDefaultParams sets common pagination params that are often used
func (p *Pagination) SetDefaultParams(ctx *Context) {
- p.AddParamIfExist("sort", ctx.Data["SortType"])
- p.AddParamIfExist("q", ctx.Data["Keyword"])
+ if v, ok := ctx.Data["SortType"].(string); ok {
+ p.AddParamString("sort", v)
+ }
+ if v, ok := ctx.Data["Keyword"].(string); ok {
+ p.AddParamString("q", v)
+ }
+ if v, ok := ctx.Data["IsFuzzy"].(bool); ok {
+ p.AddParamString("fuzzy", fmt.Sprint(v))
+ }
// do not add any more uncommon params here!
- p.AddParamIfExist("fuzzy", ctx.Data["IsFuzzy"])
}