1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-09 03:45:22 +02:00

Refactor HTTP request context (#17979)

This commit is contained in:
wxiaoguang 2021-12-15 14:59:57 +08:00 committed by GitHub
parent 9d943bf374
commit 4da1d97810
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 139 additions and 177 deletions

View file

@ -71,5 +71,5 @@ func SetDefaultBranch(ctx *gitea_context.PrivateContext) {
})
return
}
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
}

View file

@ -134,7 +134,7 @@ func HookPreReceive(ctx *gitea_context.PrivateContext) {
}
}
ctx.PlainText(http.StatusOK, []byte("ok"))
ctx.PlainText(http.StatusOK, "ok")
}
func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID, refFullName string) {

View file

@ -28,7 +28,7 @@ func UpdatePublicKeyInRepo(ctx *context.PrivateContext) {
deployKey, err := asymkey_model.GetDeployKeyByRepo(keyID, repoID)
if err != nil {
if asymkey_model.IsErrDeployKeyNotExist(err) {
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
return
}
ctx.JSON(http.StatusInternalServerError, private.Response{
@ -44,7 +44,7 @@ func UpdatePublicKeyInRepo(ctx *context.PrivateContext) {
return
}
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
}
// AuthorizedPublicKeyByContent searches content as prefix (leak e-mail part)
@ -59,5 +59,5 @@ func AuthorizedPublicKeyByContent(ctx *context.PrivateContext) {
})
return
}
ctx.PlainText(http.StatusOK, []byte(publicKey.AuthorizedString()))
ctx.PlainText(http.StatusOK, publicKey.AuthorizedString())
}

View file

@ -86,5 +86,5 @@ func sendEmail(ctx *context.PrivateContext, subject, message string, to []string
wasSent := strconv.Itoa(len(to))
ctx.PlainText(http.StatusOK, []byte(wasSent))
ctx.PlainText(http.StatusOK, wasSent)
}

View file

@ -41,19 +41,19 @@ func FlushQueues(ctx *context.PrivateContext) {
Err: fmt.Sprintf("%v", err),
})
}
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
}
// PauseLogging pauses logging
func PauseLogging(ctx *context.PrivateContext) {
log.Pause()
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
}
// ResumeLogging resumes logging
func ResumeLogging(ctx *context.PrivateContext) {
log.Resume()
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
}
// ReleaseReopenLogging releases and reopens logging files
@ -64,7 +64,7 @@ func ReleaseReopenLogging(ctx *context.PrivateContext) {
})
return
}
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
}
// RemoveLogger removes a logger
@ -81,7 +81,7 @@ func RemoveLogger(ctx *context.PrivateContext) {
if ok {
setting.RemoveSubLogDescription(group, name)
}
ctx.PlainText(http.StatusOK, []byte(fmt.Sprintf("Removed %s %s", group, name)))
ctx.PlainText(http.StatusOK, fmt.Sprintf("Removed %s %s", group, name))
}
// AddLogger adds a logger
@ -154,5 +154,5 @@ func AddLogger(ctx *context.PrivateContext) {
Config: config,
})
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
}

View file

@ -17,12 +17,12 @@ import (
// Restart causes the server to perform a graceful restart
func Restart(ctx *context.PrivateContext) {
graceful.GetManager().DoGracefulRestart()
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
}
// Shutdown causes the server to perform a graceful shutdown
func Shutdown(ctx *context.PrivateContext) {
graceful.GetManager().DoGracefulShutdown()
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
}

View file

@ -25,5 +25,5 @@ func Restart(ctx *context.PrivateContext) {
// Shutdown causes the server to perform a graceful shutdown
func Shutdown(ctx *context.PrivateContext) {
graceful.GetManager().DoGracefulShutdown()
ctx.PlainText(http.StatusOK, []byte("success"))
ctx.PlainText(http.StatusOK, "success")
}