From b2e301651bc106b2692595fd02122297d38ff586 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 25 Aug 2016 13:36:21 +0100 Subject: [PATCH] Be less excited about logging; use res.ContentLength --- .../matrix-org/go-neb/matrix/matrix.go | 17 +++++++---------- .../matrix-org/go-neb/services/giphy/giphy.go | 3 +-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/matrix/matrix.go b/src/github.com/matrix-org/go-neb/matrix/matrix.go index 9e59bb3..3911cf8 100644 --- a/src/github.com/matrix-org/go-neb/matrix/matrix.go +++ b/src/github.com/matrix-org/go-neb/matrix/matrix.go @@ -135,24 +135,21 @@ func (cli *Client) UploadLink(link string) (string, error) { if err != nil { return "", err } - log.Print("GOT GIF BODY ", link) - return cli.UploadToContentRepo(res.Body, res.Header.Get("Content-Type"), res.Header.Get("Content-Length")) + return cli.UploadToContentRepo(res.Body, res.Header.Get("Content-Type"), res.ContentLength) } // UploadToContentRepo uploads the given bytes to the content repository and returns an MXC URI. -func (cli *Client) UploadToContentRepo(content io.Reader, contentType, contentLength string) (string, error) { +func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, contentLength int64) (string, error) { req, err := http.NewRequest("POST", cli.buildBaseURL("_matrix/media/r0/upload"), content) if err != nil { return "", err } req.Header.Set("Content-Type", contentType) - cl, err := strconv.Atoi(contentLength) - if err != nil { - return "", err - } - req.ContentLength = int64(cl) - log.Print("Doing upload request to ", req.URL) - log.Print("Type=", contentType, "Length=", contentLength) + req.ContentLength = contentLength + log.WithFields(log.Fields{ + "content_type": contentType, + "content_length": contentLength, + }).Print("Uploading to content repo") res, err := cli.httpClient.Do(req) if res != nil { defer res.Body.Close() diff --git a/src/github.com/matrix-org/go-neb/services/giphy/giphy.go b/src/github.com/matrix-org/go-neb/services/giphy/giphy.go index d3502ce..b8b34c3 100644 --- a/src/github.com/matrix-org/go-neb/services/giphy/giphy.go +++ b/src/github.com/matrix-org/go-neb/services/giphy/giphy.go @@ -62,12 +62,10 @@ func (s *giphyService) cmdGiphy(client *matrix.Client, roomID, userID string, ar if err != nil { return nil, err } - log.Print("GOT ", gifResult) mxc, err := client.UploadLink(gifResult.Images.Original.URL) if err != nil { return nil, err } - log.Print("GOT MXC ", mxc) return matrix.ImageMessage{ MsgType: "m.image", @@ -84,6 +82,7 @@ func (s *giphyService) cmdGiphy(client *matrix.Client, roomID, userID string, ar // searchGiphy returns info about a gif func (s *giphyService) searchGiphy(query string) (*result, error) { + log.Info("Searching giphy for ", query) u, err := url.Parse("http://api.giphy.com/v1/gifs/search") if err != nil { return nil, err