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,9 +4,11 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (api *API) InitReaction() {
|
||||
@@ -44,7 +46,9 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(reaction.ToJson()))
|
||||
if err := json.NewEncoder(w).Encode(reaction); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func getReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Ссылка в новой задаче
Block a user