diff options
author | zeripath <art27@cantab.net> | 2021-02-19 21:36:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-19 22:36:43 +0100 |
commit | aa4f9180e4932a9813e898bf3bd9ac91924eeb03 (patch) | |
tree | e181203ffc52a8bb1740fdb81aeeeba5183c42bf /routers | |
parent | 39aa11f9c0d8aabd188f543d60752e0b8ff95cc5 (diff) | |
download | gitea-aa4f9180e4932a9813e898bf3bd9ac91924eeb03.tar.gz gitea-aa4f9180e4932a9813e898bf3bd9ac91924eeb03.zip |
Clarify the suffices and prefixes of setting.AppSubURL and setting.AppURL (#12999)
Also removes some unnecessary uses of fmt.Sprintf and adds documentation
strings
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/admin.go | 22 | ||||
-rw-r--r-- | routers/api/v1/org/member.go | 4 | ||||
-rw-r--r-- | routers/repo/search.go | 3 | ||||
-rw-r--r-- | routers/user/notification.go | 2 | ||||
-rw-r--r-- | routers/utils/utils_test.go | 2 |
5 files changed, 15 insertions, 18 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go index c8f9d8b35b..2b2328a93a 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -364,7 +364,7 @@ func WorkerCancel(ctx *context.Context) { mq.CancelWorkers(pid) ctx.Flash.Info(ctx.Tr("admin.monitor.queue.pool.cancelling")) ctx.JSON(200, map[string]interface{}{ - "redirect": setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid), + "redirect": setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10), }) } @@ -387,7 +387,7 @@ func Flush(ctx *context.Context) { log.Error("Flushing failure for %s: Error %v", mq.Name, err) } }() - ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid)) + ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10)) } // AddWorkers adds workers to a worker group @@ -401,23 +401,23 @@ func AddWorkers(ctx *context.Context) { number := ctx.QueryInt("number") if number < 1 { ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.addworkers.mustnumbergreaterzero")) - ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid)) + ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10)) return } timeout, err := time.ParseDuration(ctx.Query("timeout")) if err != nil { ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.addworkers.musttimeoutduration")) - ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid)) + ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10)) return } if _, ok := mq.Managed.(queue.ManagedPool); !ok { ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.none")) - ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid)) + ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10)) return } mq.AddWorkers(number, timeout) ctx.Flash.Success(ctx.Tr("admin.monitor.queue.pool.added")) - ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid)) + ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10)) } // SetQueueSettings sets the maximum number of workers and other settings for this queue @@ -430,7 +430,7 @@ func SetQueueSettings(ctx *context.Context) { } if _, ok := mq.Managed.(queue.ManagedPool); !ok { ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.none")) - ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid)) + ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10)) return } @@ -445,7 +445,7 @@ func SetQueueSettings(ctx *context.Context) { maxNumber, err = strconv.Atoi(maxNumberStr) if err != nil { ctx.Flash.Error(ctx.Tr("admin.monitor.queue.settings.maxnumberworkers.error")) - ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid)) + ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10)) return } if maxNumber < -1 { @@ -459,7 +459,7 @@ func SetQueueSettings(ctx *context.Context) { number, err = strconv.Atoi(numberStr) if err != nil || number < 0 { ctx.Flash.Error(ctx.Tr("admin.monitor.queue.settings.numberworkers.error")) - ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid)) + ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10)) return } } else { @@ -470,7 +470,7 @@ func SetQueueSettings(ctx *context.Context) { timeout, err = time.ParseDuration(timeoutStr) if err != nil { ctx.Flash.Error(ctx.Tr("admin.monitor.queue.settings.timeout.error")) - ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid)) + ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10)) return } } else { @@ -479,5 +479,5 @@ func SetQueueSettings(ctx *context.Context) { mq.SetPoolSettings(maxNumber, number, timeout) ctx.Flash.Success(ctx.Tr("admin.monitor.queue.settings.changed")) - ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid)) + ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10)) } diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go index 75ae1191a5..5f0e36386e 100644 --- a/routers/api/v1/org/member.go +++ b/routers/api/v1/org/member.go @@ -5,7 +5,6 @@ package org import ( - "fmt" "net/http" "code.gitea.io/gitea/models" @@ -153,8 +152,7 @@ func IsMember(ctx *context.APIContext) { } } - redirectURL := fmt.Sprintf("%sapi/v1/orgs/%s/public_members/%s", - setting.AppURL, ctx.Org.Organization.Name, userToCheck.Name) + redirectURL := setting.AppURL + "api/v1/orgs/" + ctx.Org.Organization.Name + "/public_members/" + userToCheck.Name ctx.Redirect(redirectURL, 302) } diff --git a/routers/repo/search.go b/routers/repo/search.go index 42fe3d7584..481b64d184 100644 --- a/routers/repo/search.go +++ b/routers/repo/search.go @@ -40,8 +40,7 @@ func Search(ctx *context.Context) { ctx.Data["Keyword"] = keyword ctx.Data["Language"] = language ctx.Data["queryType"] = queryType - ctx.Data["SourcePath"] = setting.AppSubURL + "/" + - path.Join(ctx.Repo.Repository.Owner.Name, ctx.Repo.Repository.Name) + ctx.Data["SourcePath"] = path.Join(setting.AppSubURL, ctx.Repo.Repository.Owner.Name, ctx.Repo.Repository.Name) ctx.Data["SearchResults"] = searchResults ctx.Data["SearchResultLanguages"] = searchResultLanguages ctx.Data["RequireHighlightJS"] = true diff --git a/routers/user/notification.go b/routers/user/notification.go index 34939d1455..523e945db9 100644 --- a/routers/user/notification.go +++ b/routers/user/notification.go @@ -174,7 +174,7 @@ func NotificationStatusPost(c *context.Context) { if c.Written() { return } - c.Data["Link"] = fmt.Sprintf("%snotifications", setting.AppURL) + c.Data["Link"] = setting.AppURL + "notifications" c.HTML(http.StatusOK, tplNotificationDiv) } diff --git a/routers/utils/utils_test.go b/routers/utils/utils_test.go index ec5e69862a..78ab3d20ee 100644 --- a/routers/utils/utils_test.go +++ b/routers/utils/utils_test.go @@ -35,7 +35,7 @@ func TestIsValidSlackChannel(t *testing.T) { } func TestIsExternalURL(t *testing.T) { - setting.AppURL = "https://try.gitea.io" + setting.AppURL = "https://try.gitea.io/" type test struct { Expected bool RawURL string |