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
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/audit"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (api *API) InitSaml() {
|
||||
@@ -230,7 +231,9 @@ func getSamlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
status := c.App.GetSamlCertificateStatus()
|
||||
w.Write([]byte(status.ToJson()))
|
||||
if err := json.NewEncoder(w).Encode(status); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func getSamlMetadataFromIdp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -252,7 +255,9 @@ func getSamlMetadataFromIdp(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(metadata.ToJson()))
|
||||
if err := json.NewEncoder(w).Encode(metadata); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func resetAuthDataToEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Ссылка в новой задаче
Block a user