diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/client.go | 9 | ||||
-rw-r--r-- | model/utils.go | 20 |
2 files changed, 21 insertions, 8 deletions
diff --git a/model/client.go b/model/client.go index a74adcd7a..f045401eb 100644 --- a/model/client.go +++ b/model/client.go @@ -997,15 +997,8 @@ func (c *Client) GetPublicLink(filename string) (*Result, *AppError) { if r, err := c.DoApiPost(c.GetTeamRoute()+"/files/get_public_link", MapToJson(map[string]string{"filename": filename})); err != nil { return nil, err } else { - var link string - if body, err := ioutil.ReadAll(r.Body); err == nil { - link = string(body) - } else { - // all the other Client methods return an empty string on invalid json, so we can too - } - return &Result{r.Header.Get(HEADER_REQUEST_ID), - r.Header.Get(HEADER_ETAG_SERVER), link}, nil + r.Header.Get(HEADER_ETAG_SERVER), StringFromJson(r.Body)}, nil } } diff --git a/model/utils.go b/model/utils.go index d9b06bd01..443a34bc4 100644 --- a/model/utils.go +++ b/model/utils.go @@ -178,6 +178,26 @@ func StringInterfaceFromJson(data io.Reader) map[string]interface{} { } } +func StringToJson(s string) string { + b, err := json.Marshal(s) + if err != nil { + return "" + } else { + return string(b) + } +} + +func StringFromJson(data io.Reader) string { + decoder := json.NewDecoder(data) + + var s string + if err := decoder.Decode(&s); err != nil { + return "" + } else { + return s + } +} + func IsLower(s string) bool { if strings.ToLower(s) == s { return true |