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
```
Этот коммит содержится в:
Agniva De Sarker
2021-07-26 13:41:02 +05:30
коммит произвёл GitHub
родитель ae7119ddf5
Коммит 23800326a0
33 изменённых файлов: 578 добавлений и 181 удалений

Просмотреть файл

@@ -11,6 +11,7 @@ import (
"io/ioutil"
"net/http"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
"github.com/mattermost/mattermost-server/v6/utils"
"github.com/mattermost/mattermost-server/v6/audit"
@@ -134,7 +135,9 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.Success()
c.LogAudit("success")
w.Write([]byte(license.ToJson()))
if err := json.NewEncoder(w).Encode(license); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
}
}
func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) {