[performance] http response encoding / writing improvements (#2374)

This commit is contained in:
kim
2023-11-27 14:00:57 +00:00
committed by GitHub
parent d7e35f6bc9
commit 74700cc803
104 changed files with 526 additions and 267 deletions

View File

@@ -124,5 +124,7 @@ func (m *Module) AccountActionPOSTHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{"message": "OK"})
apiutil.JSON(c, http.StatusOK, map[string]string{
"message": "OK",
})
}

View File

@@ -132,7 +132,9 @@ func (m *Module) DomainKeysExpirePOSTHandler(c *gin.Context) {
return
}
c.JSON(http.StatusAccepted, &apimodel.AdminActionResponse{ActionID: actionID})
apiutil.JSON(c, http.StatusOK, &apimodel.AdminActionResponse{
ActionID: actionID,
})
}
func validateDomainKeysExpire(form *apimodel.DomainKeysExpireRequest) error {

View File

@@ -122,7 +122,7 @@ func (m *Module) createDomainPermissions(
return
}
c.JSON(http.StatusOK, domainBlock)
apiutil.JSON(c, http.StatusOK, domainBlock)
return
}
@@ -158,7 +158,7 @@ func (m *Module) createDomainPermissions(
domainPerms = append(domainPerms, entry.Resource)
}
c.JSON(http.StatusOK, domainPerms)
apiutil.JSON(c, http.StatusOK, domainPerms)
}
// deleteDomainPermission deletes a single domain permission (block or allow).
@@ -200,7 +200,7 @@ func (m *Module) deleteDomainPermission(
return
}
c.JSON(http.StatusOK, domainPerm)
apiutil.JSON(c, http.StatusOK, domainPerm)
}
// getDomainPermission gets a single domain permission (block or allow).
@@ -248,7 +248,7 @@ func (m *Module) getDomainPermission(
return
}
c.JSON(http.StatusOK, domainPerm)
apiutil.JSON(c, http.StatusOK, domainPerm)
}
// getDomainPermissions gets all domain permissions of the given type (block, allow).
@@ -290,5 +290,5 @@ func (m *Module) getDomainPermissions(
return
}
c.JSON(http.StatusOK, domainPerm)
apiutil.JSON(c, http.StatusOK, domainPerm)
}

View File

@@ -116,5 +116,7 @@ func (m *Module) EmailTestPOSTHandler(c *gin.Context) {
return
}
c.JSON(http.StatusAccepted, gin.H{"status": "test email sent"})
apiutil.JSON(c, http.StatusAccepted, map[string]string{
"status": "test email sent",
})
}

View File

@@ -89,5 +89,5 @@ func (m *Module) EmojiCategoriesGETHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, categories)
apiutil.JSON(c, http.StatusOK, categories)
}

View File

@@ -131,7 +131,7 @@ func (m *Module) EmojiCreatePOSTHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, apiEmoji)
apiutil.JSON(c, http.StatusOK, apiEmoji)
}
func validateCreateEmoji(form *apimodel.EmojiCreateRequest) error {

View File

@@ -105,5 +105,5 @@ func (m *Module) EmojiDELETEHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, emoji)
apiutil.JSON(c, http.StatusOK, emoji)
}

View File

@@ -95,5 +95,5 @@ func (m *Module) EmojiGETHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, emoji)
apiutil.JSON(c, http.StatusOK, emoji)
}

View File

@@ -206,5 +206,6 @@ func (m *Module) EmojisGETHandler(c *gin.Context) {
if resp.LinkHeader != "" {
c.Header("Link", resp.LinkHeader)
}
c.JSON(http.StatusOK, resp.Items)
apiutil.JSON(c, http.StatusOK, resp.Items)
}

View File

@@ -161,7 +161,7 @@ func (m *Module) EmojiPATCHHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, emoji)
apiutil.JSON(c, http.StatusOK, emoji)
}
// do a first pass on the form here

View File

@@ -102,5 +102,5 @@ func (m *Module) MediaCleanupPOSTHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, remoteCacheDays)
apiutil.JSON(c, http.StatusOK, remoteCacheDays)
}

View File

@@ -88,5 +88,5 @@ func (m *Module) MediaRefetchPOSTHandler(c *gin.Context) {
return
}
c.Status(http.StatusAccepted)
apiutil.Data(c, http.StatusOK, apiutil.AppJSON, apiutil.StatusAcceptedJSON)
}

View File

@@ -98,5 +98,5 @@ func (m *Module) ReportGETHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, report)
apiutil.JSON(c, http.StatusOK, report)
}

View File

@@ -120,5 +120,5 @@ func (m *Module) ReportResolvePOSTHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, report)
apiutil.JSON(c, http.StatusOK, report)
}

View File

@@ -176,5 +176,6 @@ func (m *Module) ReportsGETHandler(c *gin.Context) {
if resp.LinkHeader != "" {
c.Header("Link", resp.LinkHeader)
}
c.JSON(http.StatusOK, resp.Items)
apiutil.JSON(c, http.StatusOK, resp.Items)
}

View File

@@ -108,7 +108,7 @@ func (m *Module) RulePOSTHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, apiRule)
apiutil.JSON(c, http.StatusOK, apiRule)
}
func validateCreateRule(form *apimodel.InstanceRuleCreateRequest) error {

View File

@@ -103,5 +103,5 @@ func (m *Module) RuleDELETEHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, apiRule)
apiutil.JSON(c, http.StatusOK, apiRule)
}

View File

@@ -98,5 +98,5 @@ func (m *Module) RuleGETHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, rule)
apiutil.JSON(c, http.StatusOK, rule)
}

View File

@@ -87,5 +87,5 @@ func (m *Module) RulesGETHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, resp)
apiutil.JSON(c, http.StatusOK, resp)
}

View File

@@ -123,5 +123,5 @@ func (m *Module) RulePATCHHandler(c *gin.Context) {
return
}
c.JSON(http.StatusOK, apiRule)
apiutil.JSON(c, http.StatusOK, apiRule)
}