From fd3d8bc32e45b7809559198328cec8fd426287ea Mon Sep 17 00:00:00 2001 From: xing Date: Fri, 7 Oct 2022 22:54:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions/feed.go | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/actions/feed.go b/actions/feed.go index c8a6a5b..d5cd422 100644 --- a/actions/feed.go +++ b/actions/feed.go @@ -52,7 +52,14 @@ func Feed(c *gin.Context) { if !isCacheExpired(c, feedCache.SetTime()) { c.Status(http.StatusNotModified) } else { - setFeed(feedCache, c) + r, err := feedCache.GetCache(c, time.Second, c) + if err != nil { + c.Status(http.StatusInternalServerError) + c.Abort() + c.Error(err) + return + } + setFeed(r[0], c, feedCache.SetTime()) } } @@ -102,20 +109,13 @@ func feed(arg ...any) (xml []string, err error) { return } -func setFeed(sliceCache *cache.SliceCache[string], c *gin.Context) { - s, err := sliceCache.GetCache(c, time.Second, c) - if err != nil { - c.Status(http.StatusInternalServerError) - c.Abort() - c.Error(err) - return - } - lastTimeGMT := sliceCache.SetTime().Format(tmp) +func setFeed(s string, c *gin.Context, t time.Time) { + lastTimeGMT := t.Format(tmp) eTag := helper.StringMd5(lastTimeGMT) c.Header("Content-Type", "application/rss+xml; charset=UTF-8") c.Header("Last-Modified", lastTimeGMT) c.Header("ETag", eTag) - c.String(http.StatusOK, s[0]) + c.String(http.StatusOK, s) } func PostFeed(c *gin.Context) { @@ -130,12 +130,7 @@ func PostFeed(c *gin.Context) { c.Error(err) return } - lastTimeGMT := postFeedCache.GetSetTime(id).Format(tmp) - eTag := helper.StringMd5(lastTimeGMT) - c.Header("Content-Type", "application/rss+xml; charset=UTF-8") - c.Header("Last-Modified", lastTimeGMT) - c.Header("ETag", eTag) - c.String(http.StatusOK, s) + setFeed(s, c, postFeedCache.GetSetTime(id)) } }