diff options
author | 6543 <6543@obermui.de> | 2021-08-11 02:31:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-11 02:31:13 +0200 |
commit | c4d70a032564f610b7215d3d3973943abbc7395f (patch) | |
tree | 2aa8fe44a1b4d0251a18ae671509d4f2439ed85d /routers/api/v1 | |
parent | 2eeae4edb685b22e926d301465d771fe7a0b0c83 (diff) | |
download | gitea-c4d70a032564f610b7215d3d3973943abbc7395f.tar.gz gitea-c4d70a032564f610b7215d3d3973943abbc7395f.zip |
Rename ctx.Form() to ctx.FormString() and move code into own file (#16571)
Followup from #16562 prepare for #16567
* Rename ctx.Form() to ctx.FormString()
* Reimplement FormX func to need less code and cpu cycles
* Move code into own file
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/admin/adopt.go | 2 | ||||
-rw-r--r-- | routers/api/v1/api.go | 2 | ||||
-rw-r--r-- | routers/api/v1/notify/repo.go | 4 | ||||
-rw-r--r-- | routers/api/v1/notify/threads.go | 2 | ||||
-rw-r--r-- | routers/api/v1/notify/user.go | 4 | ||||
-rw-r--r-- | routers/api/v1/org/label.go | 2 | ||||
-rw-r--r-- | routers/api/v1/org/team.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/commits.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 22 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_tracked_time.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/key.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/label.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/milestone.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/release_attachment.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 16 | ||||
-rw-r--r-- | routers/api/v1/repo/topic.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/key.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/user.go | 2 | ||||
-rw-r--r-- | routers/api/v1/utils/utils.go | 2 |
19 files changed, 41 insertions, 41 deletions
diff --git a/routers/api/v1/admin/adopt.go b/routers/api/v1/admin/adopt.go index fb5888f083..062cee6283 100644 --- a/routers/api/v1/admin/adopt.go +++ b/routers/api/v1/admin/adopt.go @@ -42,7 +42,7 @@ func ListUnadoptedRepositories(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" listOptions := utils.GetListOptions(ctx) - repoNames, count, err := repository.ListUnadoptedRepositories(ctx.Form("query"), &listOptions) + repoNames, count, err := repository.ListUnadoptedRepositories(ctx.FormString("query"), &listOptions) if err != nil { ctx.InternalServerError(err) } diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index b2202254da..6de47ddc7e 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -93,7 +93,7 @@ import ( func sudo() func(ctx *context.APIContext) { return func(ctx *context.APIContext) { - sudo := ctx.Form("sudo") + sudo := ctx.FormString("sudo") if len(sudo) == 0 { sudo = ctx.Req.Header.Get("Sudo") } diff --git a/routers/api/v1/notify/repo.go b/routers/api/v1/notify/repo.go index b5a6d8abf0..0bc48aeb16 100644 --- a/routers/api/v1/notify/repo.go +++ b/routers/api/v1/notify/repo.go @@ -171,7 +171,7 @@ func ReadRepoNotifications(ctx *context.APIContext) { // "$ref": "#/responses/empty" lastRead := int64(0) - qLastRead := strings.Trim(ctx.Form("last_read_at"), " ") + qLastRead := strings.Trim(ctx.FormString("last_read_at"), " ") if len(qLastRead) > 0 { tmpLastRead, err := time.Parse(time.RFC3339, qLastRead) if err != nil { @@ -200,7 +200,7 @@ func ReadRepoNotifications(ctx *context.APIContext) { return } - targetStatus := statusStringToNotificationStatus(ctx.Form("to-status")) + targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status")) if targetStatus == 0 { targetStatus = models.NotificationStatusRead } diff --git a/routers/api/v1/notify/threads.go b/routers/api/v1/notify/threads.go index 0865d12156..1774c0b412 100644 --- a/routers/api/v1/notify/threads.go +++ b/routers/api/v1/notify/threads.go @@ -82,7 +82,7 @@ func ReadThread(ctx *context.APIContext) { return } - targetStatus := statusStringToNotificationStatus(ctx.Form("to-status")) + targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status")) if targetStatus == 0 { targetStatus = models.NotificationStatusRead } diff --git a/routers/api/v1/notify/user.go b/routers/api/v1/notify/user.go index 184091544a..c4b126c567 100644 --- a/routers/api/v1/notify/user.go +++ b/routers/api/v1/notify/user.go @@ -122,7 +122,7 @@ func ReadNotifications(ctx *context.APIContext) { // "$ref": "#/responses/empty" lastRead := int64(0) - qLastRead := strings.Trim(ctx.Form("last_read_at"), " ") + qLastRead := strings.Trim(ctx.FormString("last_read_at"), " ") if len(qLastRead) > 0 { tmpLastRead, err := time.Parse(time.RFC3339, qLastRead) if err != nil { @@ -147,7 +147,7 @@ func ReadNotifications(ctx *context.APIContext) { return } - targetStatus := statusStringToNotificationStatus(ctx.Form("to-status")) + targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status")) if targetStatus == 0 { targetStatus = models.NotificationStatusRead } diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go index a66977ea5a..c70252158e 100644 --- a/routers/api/v1/org/label.go +++ b/routers/api/v1/org/label.go @@ -43,7 +43,7 @@ func ListLabels(ctx *context.APIContext) { // "200": // "$ref": "#/responses/LabelList" - labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.Form("sort"), utils.GetListOptions(ctx)) + labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetLabelsByOrgID", err) return diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index e967fc7612..7802bede1b 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -658,9 +658,9 @@ func SearchTeam(ctx *context.APIContext) { opts := &models.SearchTeamOptions{ UserID: ctx.User.ID, - Keyword: strings.TrimSpace(ctx.Form("q")), + Keyword: strings.TrimSpace(ctx.FormString("q")), OrgID: ctx.Org.Organization.ID, - IncludeDesc: ctx.Form("include_desc") == "" || ctx.FormBool("include_desc"), + IncludeDesc: ctx.FormString("include_desc") == "" || ctx.FormBool("include_desc"), ListOptions: listOptions, } diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go index 9950a7d456..f2fd901efa 100644 --- a/routers/api/v1/repo/commits.go +++ b/routers/api/v1/repo/commits.go @@ -147,7 +147,7 @@ func GetAllCommits(ctx *context.APIContext) { listOptions.PageSize = setting.Git.CommitsRangeSize } - sha := ctx.Form("sha") + sha := ctx.FormString("sha") var baseCommit *git.Commit if len(sha) == 0 { diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 172ad48031..6add20cb09 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -106,7 +106,7 @@ func SearchIssues(ctx *context.APIContext) { } var isClosed util.OptionalBool - switch ctx.Form("state") { + switch ctx.FormString("state") { case "closed": isClosed = util.OptionalBoolTrue case "all": @@ -140,7 +140,7 @@ func SearchIssues(ctx *context.APIContext) { var issues []*models.Issue var filteredCount int64 - keyword := strings.Trim(ctx.Form("q"), " ") + keyword := strings.Trim(ctx.FormString("q"), " ") if strings.IndexByte(keyword, 0) >= 0 { keyword = "" } @@ -153,7 +153,7 @@ func SearchIssues(ctx *context.APIContext) { } var isPull util.OptionalBool - switch ctx.Form("type") { + switch ctx.FormString("type") { case "pulls": isPull = util.OptionalBoolTrue case "issues": @@ -162,13 +162,13 @@ func SearchIssues(ctx *context.APIContext) { isPull = util.OptionalBoolNone } - labels := strings.TrimSpace(ctx.Form("labels")) + labels := strings.TrimSpace(ctx.FormString("labels")) var includedLabelNames []string if len(labels) > 0 { includedLabelNames = strings.Split(labels, ",") } - milestones := strings.TrimSpace(ctx.Form("milestones")) + milestones := strings.TrimSpace(ctx.FormString("milestones")) var includedMilestones []string if len(milestones) > 0 { includedMilestones = strings.Split(milestones, ",") @@ -319,7 +319,7 @@ func ListIssues(ctx *context.APIContext) { } var isClosed util.OptionalBool - switch ctx.Form("state") { + switch ctx.FormString("state") { case "closed": isClosed = util.OptionalBoolTrue case "all": @@ -331,7 +331,7 @@ func ListIssues(ctx *context.APIContext) { var issues []*models.Issue var filteredCount int64 - keyword := strings.Trim(ctx.Form("q"), " ") + keyword := strings.Trim(ctx.FormString("q"), " ") if strings.IndexByte(keyword, 0) >= 0 { keyword = "" } @@ -345,7 +345,7 @@ func ListIssues(ctx *context.APIContext) { } } - if splitted := strings.Split(ctx.Form("labels"), ","); len(splitted) > 0 { + if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 { labelIDs, err = models.GetLabelIDsInRepoByNames(ctx.Repo.Repository.ID, splitted) if err != nil { ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err) @@ -354,7 +354,7 @@ func ListIssues(ctx *context.APIContext) { } var mileIDs []int64 - if part := strings.Split(ctx.Form("milestones"), ","); len(part) > 0 { + if part := strings.Split(ctx.FormString("milestones"), ","); len(part) > 0 { for i := range part { // uses names and fall back to ids // non existent milestones are discarded @@ -386,7 +386,7 @@ func ListIssues(ctx *context.APIContext) { listOptions := utils.GetListOptions(ctx) var isPull util.OptionalBool - switch ctx.Form("type") { + switch ctx.FormString("type") { case "pulls": isPull = util.OptionalBoolTrue case "issues": @@ -448,7 +448,7 @@ func ListIssues(ctx *context.APIContext) { } func getUserIDForFilter(ctx *context.APIContext, queryName string) int64 { - userName := ctx.Form(queryName) + userName := ctx.FormString(queryName) if len(userName) == 0 { return 0 } diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index eaf2c44c7c..e2935fd13d 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -90,7 +90,7 @@ func ListTrackedTimes(ctx *context.APIContext) { IssueID: issue.ID, } - qUser := strings.Trim(ctx.Form("user"), " ") + qUser := strings.Trim(ctx.FormString("user"), " ") if qUser != "" { user, err := models.GetUserByName(qUser) if models.IsErrUserNotExist(err) { @@ -500,7 +500,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) { } // Filters - qUser := strings.Trim(ctx.Form("user"), " ") + qUser := strings.Trim(ctx.FormString("user"), " ") if qUser != "" { user, err := models.GetUserByName(qUser) if models.IsErrUserNotExist(err) { diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go index d41531dd58..903cef7104 100644 --- a/routers/api/v1/repo/key.go +++ b/routers/api/v1/repo/key.go @@ -78,7 +78,7 @@ func ListDeployKeys(ctx *context.APIContext) { var keys []*models.DeployKey var err error - fingerprint := ctx.Form("fingerprint") + fingerprint := ctx.FormString("fingerprint") keyID := ctx.FormInt64("key_id") if fingerprint != "" || keyID != 0 { keys, err = models.SearchDeployKeys(ctx.Repo.Repository.ID, keyID, fingerprint) diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index 0d1368d18c..ca0d8392b8 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -49,7 +49,7 @@ func ListLabels(ctx *context.APIContext) { // "200": // "$ref": "#/responses/LabelList" - labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Form("sort"), utils.GetListOptions(ctx)) + labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetLabelsByRepoID", err) return diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go index 1231c3eb21..07b3897bc1 100644 --- a/routers/api/v1/repo/milestone.go +++ b/routers/api/v1/repo/milestone.go @@ -60,8 +60,8 @@ func ListMilestones(ctx *context.APIContext) { milestones, err := models.GetMilestones(models.GetMilestonesOption{ ListOptions: utils.GetListOptions(ctx), RepoID: ctx.Repo.Repository.ID, - State: api.StateType(ctx.Form("state")), - Name: ctx.Form("name"), + State: api.StateType(ctx.FormString("state")), + Name: ctx.FormString("name"), }) if err != nil { ctx.Error(http.StatusInternalServerError, "GetMilestones", err) diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go index 7986c47e6f..0834667657 100644 --- a/routers/api/v1/repo/release_attachment.go +++ b/routers/api/v1/repo/release_attachment.go @@ -190,7 +190,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) { } var filename = header.Filename - if query := ctx.Form("name"); query != "" { + if query := ctx.FormString("name"); query != "" { filename = query } diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 9c93408832..fb1472226f 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -135,19 +135,19 @@ func Search(ctx *context.APIContext) { opts := &models.SearchRepoOptions{ ListOptions: utils.GetListOptions(ctx), Actor: ctx.User, - Keyword: strings.Trim(ctx.Form("q"), " "), + Keyword: strings.Trim(ctx.FormString("q"), " "), OwnerID: ctx.FormInt64("uid"), PriorityOwnerID: ctx.FormInt64("priority_owner_id"), TeamID: ctx.FormInt64("team_id"), TopicOnly: ctx.FormBool("topic"), Collaborate: util.OptionalBoolNone, - Private: ctx.IsSigned && (ctx.Form("private") == "" || ctx.FormBool("private")), + Private: ctx.IsSigned && (ctx.FormString("private") == "" || ctx.FormBool("private")), Template: util.OptionalBoolNone, StarredByID: ctx.FormInt64("starredBy"), IncludeDescription: ctx.FormBool("includeDesc"), } - if ctx.Form("template") != "" { + if ctx.FormString("template") != "" { opts.Template = util.OptionalBoolOf(ctx.FormBool("template")) } @@ -155,7 +155,7 @@ func Search(ctx *context.APIContext) { opts.Collaborate = util.OptionalBoolFalse } - var mode = ctx.Form("mode") + var mode = ctx.FormString("mode") switch mode { case "source": opts.Fork = util.OptionalBoolFalse @@ -173,17 +173,17 @@ func Search(ctx *context.APIContext) { return } - if ctx.Form("archived") != "" { + if ctx.FormString("archived") != "" { opts.Archived = util.OptionalBoolOf(ctx.FormBool("archived")) } - if ctx.Form("is_private") != "" { + if ctx.FormString("is_private") != "" { opts.IsPrivate = util.OptionalBoolOf(ctx.FormBool("is_private")) } - var sortMode = ctx.Form("sort") + var sortMode = ctx.FormString("sort") if len(sortMode) > 0 { - var sortOrder = ctx.Form("order") + var sortOrder = ctx.FormString("order") if len(sortOrder) == 0 { sortOrder = "asc" } diff --git a/routers/api/v1/repo/topic.go b/routers/api/v1/repo/topic.go index 7646eaf82e..a7c52e0bcc 100644 --- a/routers/api/v1/repo/topic.go +++ b/routers/api/v1/repo/topic.go @@ -274,7 +274,7 @@ func TopicSearch(ctx *context.APIContext) { return } - kw := ctx.Form("q") + kw := ctx.FormString("q") listOptions := utils.GetListOptions(ctx) diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go index 284653b108..04252524b7 100644 --- a/routers/api/v1/user/key.go +++ b/routers/api/v1/user/key.go @@ -48,7 +48,7 @@ func listPublicKeys(ctx *context.APIContext, user *models.User) { var keys []*models.PublicKey var err error - fingerprint := ctx.Form("fingerprint") + fingerprint := ctx.FormString("fingerprint") username := ctx.Params("username") if fingerprint != "" { diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index de1fd5a5c5..db950bd1ee 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -58,7 +58,7 @@ func Search(ctx *context.APIContext) { opts := &models.SearchUserOptions{ Actor: ctx.User, - Keyword: strings.Trim(ctx.Form("q"), " "), + Keyword: strings.Trim(ctx.FormString("q"), " "), UID: ctx.FormInt64("uid"), Type: models.UserTypeIndividual, ListOptions: listOptions, diff --git a/routers/api/v1/utils/utils.go b/routers/api/v1/utils/utils.go index ee70723bd1..81f5086c96 100644 --- a/routers/api/v1/utils/utils.go +++ b/routers/api/v1/utils/utils.go @@ -54,7 +54,7 @@ func parseTime(value string) (int64, error) { // prepareQueryArg unescape and trim a query arg func prepareQueryArg(ctx *context.APIContext, name string) (value string, err error) { - value, err = url.PathUnescape(ctx.Form(name)) + value, err = url.PathUnescape(ctx.FormString(name)) value = strings.TrimSpace(value) return } |