From f358a74079a3d030f35f1441449df9854b655274 Mon Sep 17 00:00:00 2001 From: nite07 Date: Mon, 2 Dec 2024 16:51:06 +0800 Subject: [PATCH] fix --- crawler/freegog.go | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/crawler/freegog.go b/crawler/freegog.go index ed568bf..b7b7b0c 100644 --- a/crawler/freegog.go +++ b/crawler/freegog.go @@ -23,8 +23,7 @@ import ( ) type FreeGOGCrawler struct { - logger *zap.Logger - session *ccs.Session + logger *zap.Logger } func NewFreeGOGCrawler(logger *zap.Logger) *FreeGOGCrawler { @@ -34,25 +33,22 @@ func NewFreeGOGCrawler(logger *zap.Logger) *FreeGOGCrawler { } func (c *FreeGOGCrawler) getWAFSession() (*ccs.Session, error) { - if c.session == nil { - if val, exist := cache.Get("freegog_waf_session"); exist { - session := ccs.Session{} - err := json.Unmarshal([]byte(val), &session) - if err != nil { - return nil, err - } - c.session = &session - } else { - session, err := ccs.WAFSession(config.Config.CFClearanceScraper.Url, constant.FreeGOGListURL) - if err != nil { - return nil, err - } - c.session = &session - jsonBytes, _ := json.Marshal(session) - _ = cache.AddWithExpire("freegog_waf_session", jsonBytes, 24*time.Hour) + var session ccs.Session + var err error + if val, exist := cache.Get("freegog_waf_session"); exist { + err := json.Unmarshal([]byte(val), &session) + if err != nil { + return nil, err } + } else { + session, err = ccs.WAFSession(config.Config.CFClearanceScraper.Url, constant.FreeGOGListURL) + if err != nil { + return nil, err + } + jsonBytes, _ := json.Marshal(session) + _ = cache.AddWithExpire("freegog_waf_session", jsonBytes, 24*time.Hour) } - return c.session, nil + return &session, nil } func (c *FreeGOGCrawler) Name() string {