diff options
author | Jesús Espino <jespinog@gmail.com> | 2018-08-01 16:55:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-01 16:55:18 +0200 |
commit | d81a61398d01d839e70e2345da787e7ef89c0832 (patch) | |
tree | a0702c7874ae31b487bb0b87dcce613edc1e53b9 /api4/post.go | |
parent | 1f168263a2ff73ddee1193cccdeea533f6d501fe (diff) | |
download | chat-d81a61398d01d839e70e2345da787e7ef89c0832.tar.gz chat-d81a61398d01d839e70e2345da787e7ef89c0832.tar.bz2 chat-d81a61398d01d839e70e2345da787e7ef89c0832.zip |
Migrate all the api4 to handle errors in idiomatic way (#9143)
Diffstat (limited to 'api4/post.go')
-rw-r--r-- | api4/post.go | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/api4/post.go b/api4/post.go index 12664cc24..2568ade0a 100644 --- a/api4/post.go +++ b/api4/post.go @@ -234,10 +234,10 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) { if c.HandleEtag(post.Etag(), "Get Post", w, r) { return - } else { - w.Header().Set(model.HEADER_ETAG_SERVER, post.Etag()) - w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(post).ToJson())) } + + w.Header().Set(model.HEADER_ETAG_SERVER, post.Etag()) + w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(post).ToJson())) } func deletePost(c *Context, w http.ResponseWriter, r *http.Request) { @@ -313,10 +313,10 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) { if c.HandleEtag(list.Etag(), "Get Post Thread", w, r) { return - } else { - w.Header().Set(model.HEADER_ETAG_SERVER, list.Etag()) - w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(list).ToJson())) } + + w.Header().Set(model.HEADER_ETAG_SERVER, list.Etag()) + w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(list).ToJson())) } func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) { @@ -487,16 +487,19 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if infos, err := c.App.GetFileInfosForPost(c.Params.PostId, false); err != nil { + infos, err := c.App.GetFileInfosForPost(c.Params.PostId, false) + if err != nil { c.Err = err return - } else if c.HandleEtag(model.GetEtagForFileInfos(infos), "Get File Infos For Post", w, r) { + } + + if c.HandleEtag(model.GetEtagForFileInfos(infos), "Get File Infos For Post", w, r) { return - } else { - w.Header().Set("Cache-Control", "max-age=2592000, public") - w.Header().Set(model.HEADER_ETAG_SERVER, model.GetEtagForFileInfos(infos)) - w.Write([]byte(model.FileInfosToJson(infos))) } + + w.Header().Set("Cache-Control", "max-age=2592000, public") + w.Header().Set(model.HEADER_ETAG_SERVER, model.GetEtagForFileInfos(infos)) + w.Write([]byte(model.FileInfosToJson(infos))) } func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) { |