MM-22051: Remove ToJson methods from network writes (#17999)
We replace the double conversion of []byte to string, with a direct write to http.ResponseWriter. https://mattermost.atlassian.net/browse/MM-22051 Tried using gofmt -r, but it only accepts Go expressions. So had to resort to an ugly sed replace sed -E -i 's/w.Write\(\[\]byte\((.*).ToJson\(\)\)\)/if err := json.NewEncoder\(w\).Encode\(\1\); err != nil { mlog.Warn\("Error while writing response", mlog.Err\(err\)\)}/g' *.go ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ae7119ddf5
Коммит
23800326a0
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
@@ -69,8 +70,10 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud {
|
||||
w.Write([]byte(cfg.ToJsonFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)))
|
||||
} else {
|
||||
w.Write([]byte(cfg.ToJson()))
|
||||
return
|
||||
}
|
||||
if err := json.NewEncoder(w).Encode(cfg); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,8 +176,11 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud {
|
||||
w.Write([]byte(cfg.ToJsonFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)))
|
||||
} else {
|
||||
w.Write([]byte(cfg.ToJson()))
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(cfg); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,8 +297,11 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud {
|
||||
w.Write([]byte(cfg.ToJsonFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)))
|
||||
} else {
|
||||
w.Write([]byte(cfg.ToJson()))
|
||||
return
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(cfg); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user