From 9cde05bf3fd74d367d6c9b39730b469a69590df6 Mon Sep 17 00:00:00 2001 From: Yader Velasquez Date: Fri, 9 Feb 2024 10:24:18 -0600 Subject: [PATCH] Use QueryParam instead of QueryParams to get url query parameters --- accounts/routes.go | 2 +- admin/routes.go | 70 ++++++++++++++++++++++----------------------- analytics/routes.go | 8 +++--- billing/routes.go | 8 +++--- core/routes.go | 52 ++++++++++++++++----------------- list/routes.go | 28 +++++++++--------- short/routes.go | 12 ++++---- slack/routes.go | 4 +-- 8 files changed, 92 insertions(+), 92 deletions(-) diff --git a/accounts/routes.go b/accounts/routes.go index 58d1e01..c6c7c85 100644 --- a/accounts/routes.go +++ b/accounts/routes.go @@ -243,7 +243,7 @@ func (s *Service) Settings(c echo.Context) error { // CompleteRegister ... func (s *Service) CompleteRegister(c echo.Context) error { - key := c.QueryParams().Get("key") + key := c.QueryParam("key") if key == "" { return echo.NotFoundHandler(c) } diff --git a/admin/routes.go b/admin/routes.go index 0577a76..227733e 100644 --- a/admin/routes.go +++ b/admin/routes.go @@ -305,10 +305,10 @@ func (s *Service) OrgDetail(c echo.Context) error { } }`) op.Var("orgSlug", result.Org.Slug) - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } err = links.Execute(c.Request().Context(), op, &historyResult) if err != nil { @@ -785,17 +785,17 @@ func (s *Service) BillingList(c echo.Context) error { intervalSelected int ) - if c.QueryParams().Get("date-start") != "" && c.QueryParams().Get("date-end") != "" { + if c.QueryParam("date-start") != "" && c.QueryParam("date-end") != "" { tz := timezone.ForContext(c.Request().Context()) loc, err := time.LoadLocation(tz) if err != nil { return err } - sDateTime, err := time.ParseInLocation("2006-01-02", c.QueryParams().Get("date-start"), loc) + sDateTime, err := time.ParseInLocation("2006-01-02", c.QueryParam("date-start"), loc) if err != nil { return echo.NotFoundHandler(c) } - eDateTime, err := time.ParseInLocation("2006-01-02", c.QueryParams().Get("date-end"), loc) + eDateTime, err := time.ParseInLocation("2006-01-02", c.QueryParam("date-end"), loc) if err != nil { return echo.NotFoundHandler(c) } @@ -805,8 +805,8 @@ func (s *Service) BillingList(c echo.Context) error { op.Var("dStart", sDate) op.Var("dEnd", eDate) filterSelector = "range" - } else if c.QueryParams().Get("interval") != "" { - interval, err := strconv.Atoi(c.QueryParams().Get("interval")) + } else if c.QueryParam("interval") != "" { + interval, err := strconv.Atoi(c.QueryParam("interval")) if err != nil { return echo.NotFoundHandler(c) } @@ -859,16 +859,16 @@ func (s *Service) BillingList(c echo.Context) error { } } }`) - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } if sDate != "" && eDate != "" { op.Var("dStart", sDate) op.Var("dEnd", eDate) - } else if c.QueryParams().Get("interval") != "" { + } else if c.QueryParam("interval") != "" { op.Var("interval", intervalSelected) } err = links.Execute(c.Request().Context(), op, &historyResult) @@ -907,7 +907,7 @@ func (s *Service) BillingList(c echo.Context) error { func (s *Service) DomainList(c echo.Context) error { gctx := c.(*server.Context) - query := c.QueryParams().Get("q") + query := c.QueryParam("q") lt := localizer.GetSessionLocalizer(c) pd := localizer.NewPageData(lt.Translate("Admin Domain Dashboard")) pd.Data["no_domains"] = lt.Translate("No Domains") @@ -1005,14 +1005,14 @@ func (s *Service) DomainList(c echo.Context) error { gmap["search"] = query } - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } - if c.QueryParams().Get("level") != "" { - level, err := strconv.Atoi(c.QueryParams().Get("level")) + if c.QueryParam("level") != "" { + level, err := strconv.Atoi(c.QueryParam("level")) if err != nil { return echo.NotFoundHandler(c) } @@ -1020,8 +1020,8 @@ func (s *Service) DomainList(c echo.Context) error { gmap["selectedLevel"] = level } - if c.QueryParams().Get("service") != "" { - service, err := strconv.Atoi(c.QueryParams().Get("service")) + if c.QueryParam("service") != "" { + service, err := strconv.Atoi(c.QueryParam("service")) if err != nil { return echo.NotFoundHandler(c) } @@ -1029,8 +1029,8 @@ func (s *Service) DomainList(c echo.Context) error { gmap["selectedService"] = service } - if c.QueryParams().Get("active") != "" { - active, err := strconv.ParseBool(c.QueryParams().Get("active")) + if c.QueryParam("active") != "" { + active, err := strconv.ParseBool(c.QueryParam("active")) if err != nil { return echo.NotFoundHandler(c) } @@ -1055,7 +1055,7 @@ func (s *Service) DomainList(c echo.Context) error { func (s *Service) OrgList(c echo.Context) error { gctx := c.(*server.Context) - query := c.QueryParams().Get("q") + query := c.QueryParam("q") lt := localizer.GetSessionLocalizer(c) pd := localizer.NewPageData(lt.Translate("Admin Organization Dashboard")) pd.Data["no_orgs"] = lt.Translate("No Organizations") @@ -1111,10 +1111,10 @@ func (s *Service) OrgList(c echo.Context) error { gmap["search"] = query } - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } err := links.Execute(c.Request().Context(), op, &result) if err != nil { @@ -1396,7 +1396,7 @@ func (s *Service) UserUpdate(c echo.Context) error { func (s *Service) UserList(c echo.Context) error { gctx := c.(*server.Context) - query := c.QueryParams().Get("q") + query := c.QueryParam("q") lt := localizer.GetSessionLocalizer(c) pd := localizer.NewPageData(lt.Translate("Admin Dashboard")) pd.Data["user_list"] = lt.Translate("User List") @@ -1444,10 +1444,10 @@ func (s *Service) UserList(c echo.Context) error { op.Var("search", query) gmap["search"] = query } - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } err := links.Execute(c.Request().Context(), op, &result) if err != nil { diff --git a/analytics/routes.go b/analytics/routes.go index 2efb9ec..a1c839c 100644 --- a/analytics/routes.go +++ b/analytics/routes.go @@ -93,12 +93,12 @@ func (s *Service) Detail(c echo.Context) error { var sDateTime time.Time var eDateTime time.Time var isRestrictedFilter bool - if c.QueryParams().Get("date-start") != "" && c.QueryParams().Get("date-end") != "" { - sDateTime, err = time.ParseInLocation("2006-01-02", c.QueryParams().Get("date-start"), loc) + if c.QueryParam("date-start") != "" && c.QueryParam("date-end") != "" { + sDateTime, err = time.ParseInLocation("2006-01-02", c.QueryParam("date-start"), loc) if err != nil { return echo.NotFoundHandler(c) } - eDateTime, err = time.ParseInLocation("2006-01-02", c.QueryParams().Get("date-end"), loc) + eDateTime, err = time.ParseInLocation("2006-01-02", c.QueryParam("date-end"), loc) if err != nil { return echo.NotFoundHandler(c) } @@ -121,7 +121,7 @@ func (s *Service) Detail(c echo.Context) error { // Used to query sDateQuery := sDateTime.UTC().Format("2006-01-02") eDateQuery := eDateTime.UTC().Format("2006-01-02") - interval := c.QueryParams().Get("interval") + interval := c.QueryParam("interval") type GraphQLResponse struct { Data AnalyticsResult `json:"analytics"` diff --git a/billing/routes.go b/billing/routes.go index 2dc9a1d..a857477 100644 --- a/billing/routes.go +++ b/billing/routes.go @@ -286,10 +286,10 @@ func (s *Service) SubscriptionHistory(c echo.Context) error { } }`) op.Var("orgSlug", slug) - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } err = links.Execute(c.Request().Context(), op, &result) if err != nil { diff --git a/core/routes.go b/core/routes.go index ad539a8..ea6f1d4 100644 --- a/core/routes.go +++ b/core/routes.go @@ -809,12 +809,12 @@ func (s *Service) OrgMembersAdd(c echo.Context) error { // OrgMemberConfirmation ... func (s *Service) OrgMemberConfirmation(c echo.Context) error { - key := c.QueryParams().Get("key") + key := c.QueryParam("key") if key == "" { return echo.NotFoundHandler(c) } - if c.QueryParams().Get("redirect") == "true" { + if c.QueryParam("redirect") == "true" { q := url.Values{} q.Set("key", key) url := c.Echo().Reverse("accounts:complete_register") + "?" + q.Encode() @@ -1066,16 +1066,16 @@ func (s *Service) OrgLinksCreate(c echo.Context) error { OrgSlug: formSlug, } - if c.QueryParams().Get("title") != "" { - form.Title = c.QueryParams().Get("title") + if c.QueryParam("title") != "" { + form.Title = c.QueryParam("title") } - if c.QueryParams().Get("description") != "" { - form.Description = c.QueryParams().Get("description") + if c.QueryParam("description") != "" { + form.Description = c.QueryParam("description") } - if c.QueryParams().Get("url") != "" { - form.URL = c.QueryParams().Get("url") + if c.QueryParam("url") != "" { + form.URL = c.QueryParam("url") } - if c.QueryParams().Get("next") == "same" { + if c.QueryParam("next") == "same" { form.Redirect = req.Referer() } @@ -1115,14 +1115,14 @@ func (s *Service) PopularLinkList(c echo.Context) error { }`) var search string - if c.QueryParams().Get("q") != "" { - search = c.QueryParams().Get("q") + if c.QueryParam("q") != "" { + search = c.QueryParam("q") op.Var("search", search) } var tag string - if c.QueryParams().Get("tag") != "" { - tag = c.QueryParams().Get("tag") + if c.QueryParam("tag") != "" { + tag = c.QueryParam("tag") op.Var("tag", tag) } @@ -1242,10 +1242,10 @@ func (s *Service) OrgLinksList(c echo.Context) error { } else { navFlag = "recent" } - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } var ( @@ -1253,10 +1253,10 @@ func (s *Service) OrgLinksList(c echo.Context) error { hasStarredFilter bool hasAllFilter bool ) - if c.QueryParams().Get("filter") != "" { - op.Var("filter", c.QueryParams().Get("filter")) + if c.QueryParam("filter") != "" { + op.Var("filter", c.QueryParam("filter")) - switch c.QueryParams().Get("filter") { + switch c.QueryParam("filter") { case links.FilterUnread: hasUnreadFilter = true case links.FilterStarred: @@ -1269,13 +1269,13 @@ func (s *Service) OrgLinksList(c echo.Context) error { } var tag string - if c.QueryParams().Get("tag") != "" { - tag = c.QueryParams().Get("tag") + if c.QueryParam("tag") != "" { + tag = c.QueryParam("tag") op.Var("tag", tag) } var search string - if c.QueryParams().Get("q") != "" { - search = c.QueryParams().Get("q") + if c.QueryParam("q") != "" { + search = c.QueryParam("q") op.Var("search", search) } @@ -1821,7 +1821,7 @@ func (s *Service) QRManageDelete(c echo.Context) error { if err != nil { return echo.NotFoundHandler(c) } - next := c.QueryParams().Get("next") + next := c.QueryParam("next") if next == "" { return echo.NotFoundHandler(c) } @@ -2225,7 +2225,7 @@ func (s *Service) OrgLinkAsRead(c echo.Context) error { func (s *Service) TagAutocomplete(c echo.Context) error { gctx := c.(*server.Context) user := gctx.User.(*models.User) - q := c.QueryParams().Get("q") + q := c.QueryParam("q") var tags []*models.Tag var err error if q != "" { diff --git a/list/routes.go b/list/routes.go index 964d2e2..cf02104 100644 --- a/list/routes.go +++ b/list/routes.go @@ -525,10 +525,10 @@ func (s *Service) ListingLinksManage(c echo.Context) error { op.Var("slug", listing.Slug) op.Var("domainId", listing.DomainID) - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } err = links.Execute(c.Request().Context(), op, &result) @@ -1006,14 +1006,14 @@ func (s *Service) ListingList(c echo.Context) error { op.Var("orgSlug", org.Slug) - if c.QueryParams().Get("tag") != "" { - op.Var("tag", c.QueryParams().Get("tag")) + if c.QueryParam("tag") != "" { + op.Var("tag", c.QueryParam("tag")) } - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } err = links.Execute(c.Request().Context(), op, &result) @@ -1506,10 +1506,10 @@ func (r *DetailService) ListDetail(c echo.Context) error { } op.Var("domainId", domain.ID) - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } err := links.Execute(c.Request().Context(), op, &result) diff --git a/short/routes.go b/short/routes.go index 0f45682..637426d 100644 --- a/short/routes.go +++ b/short/routes.go @@ -113,14 +113,14 @@ func (s *Service) LinkShortList(c echo.Context) error { op.Var("slug", slug) - if c.QueryParams().Get("tag") != "" { - op.Var("tag", c.QueryParams().Get("tag")) + if c.QueryParam("tag") != "" { + op.Var("tag", c.QueryParam("tag")) } - if c.QueryParams().Get("next") != "" { - op.Var("after", c.QueryParams().Get("next")) - } else if c.QueryParams().Get("prev") != "" { - op.Var("before", c.QueryParams().Get("prev")) + if c.QueryParam("next") != "" { + op.Var("after", c.QueryParam("next")) + } else if c.QueryParam("prev") != "" { + op.Var("before", c.QueryParam("prev")) } err = links.Execute(c.Request().Context(), op, &result) diff --git a/slack/routes.go b/slack/routes.go index f86dd30..9ce3428 100644 --- a/slack/routes.go +++ b/slack/routes.go @@ -281,7 +281,7 @@ func (s *Service) ConnectSlack(c echo.Context) error { pd.Data["confirm"] = lt.Translate("Do you want to connect with slack?") user := gctx.User.(*models.User) - orgSlug := c.QueryParams().Get("state") + orgSlug := c.QueryParam("state") if orgSlug == "" { return echo.NotFoundHandler(c) @@ -314,7 +314,7 @@ func (s *Service) ConnectSlack(c echo.Context) error { "orgSlug": orgSlug, } - code := c.QueryParams().Get("code") + code := c.QueryParam("code") if code != "" { slackURL, ok := gctx.Server.Config.File.Get("slack", "oauth-access-url") if !ok { -- 2.45.2