@@ -14,7 +14,7 @@ import (
1414 "github.com/mmcdole/gofeed"
1515)
1616
17- type FeedGetter struct {
17+ type Fetcher struct {
1818 redisClient * redis.Client
1919 s3Client * s3.Client
2020 httpClient * http.Client
@@ -32,20 +32,20 @@ type FeedResponse struct {
3232 StatusMessage string `json:"statusMessage,omitempty"`
3333}
3434
35- func NewFeedGetter (redisClient * redis.Client , s3Client * s3.Client , s3Bucket string ) * FeedGetter {
36- return & FeedGetter {
35+ func NewFetcher (redisClient * redis.Client , s3Client * s3.Client , s3Bucket string ) * Fetcher {
36+ return & Fetcher {
3737 redisClient : redisClient ,
3838 s3Client : s3Client ,
3939 httpClient : & http.Client {},
4040 s3Bucket : s3Bucket ,
4141 }
4242}
4343
44- func (fg * FeedGetter ) Get (ctx context.Context , feedURI string ) (* FeedResponse , error ) {
44+ func (f * Fetcher ) FetchFeed (ctx context.Context , feedURI string ) (* FeedResponse , error ) {
4545 keys := BuildRedisKeys (feedURI )
4646
4747 // Fetch stored feed metadata from Redis
48- storedFeed , err := fg .redisClient .HGetAll (ctx , keys .FeedKey ).Result ()
48+ storedFeed , err := f .redisClient .HGetAll (ctx , keys .FeedKey ).Result ()
4949 if err != nil && err != redis .Nil {
5050 return nil , fmt .Errorf ("failed to get stored feed: %w" , err )
5151 }
@@ -63,7 +63,7 @@ func (fg *FeedGetter) Get(ctx context.Context, feedURI string) (*FeedResponse, e
6363 req .Header .Set (key , value )
6464 }
6565
66- resp , err := fg .httpClient .Do (req )
66+ resp , err := f .httpClient .Do (req )
6767 if err != nil {
6868 return & FeedResponse {
6969 Success : false ,
@@ -75,7 +75,7 @@ func (fg *FeedGetter) Get(ctx context.Context, feedURI string) (*FeedResponse, e
7575 // Handle HTTP status codes
7676 if resp .StatusCode == http .StatusNotModified {
7777 // Feed not modified, return cached articles
78- articles , err := fg .getArticleIds (ctx , keys .ArticlesKey )
78+ articles , err := f .getArticleIds (ctx , keys .ArticlesKey )
7979 if err != nil {
8080 return nil , err
8181 }
@@ -124,7 +124,7 @@ func (fg *FeedGetter) Get(ctx context.Context, feedURI string) (*FeedResponse, e
124124 "etag" : etag ,
125125 }
126126
127- if err := fg .redisClient .HMSet (ctx , keys .FeedKey , feedMeta ).Err (); err != nil {
127+ if err := f .redisClient .HMSet (ctx , keys .FeedKey , feedMeta ).Err (); err != nil {
128128 return nil , fmt .Errorf ("failed to store feed metadata: %w" , err )
129129 }
130130
@@ -153,15 +153,15 @@ func (fg *FeedGetter) Get(ctx context.Context, feedURI string) (*FeedResponse, e
153153 articleKey := BuildArticleKey (processedArticle .Hash )
154154
155155 // Get old score from Redis
156- oldScoreStr , err := fg .redisClient .ZScore (ctx , keys .ArticlesKey , articleKey ).Result ()
156+ oldScoreStr , err := f .redisClient .ZScore (ctx , keys .ArticlesKey , articleKey ).Result ()
157157 var oldScore * string
158158 if err == nil {
159159 scoreStr := strconv .FormatInt (int64 (oldScoreStr ), 10 )
160160 oldScore = & scoreStr
161161 }
162162
163163 // Add article to sorted set
164- err = fg .redisClient .ZAdd (ctx , keys .ArticlesKey , & redis.Z {
164+ err = f .redisClient .ZAdd (ctx , keys .ArticlesKey , & redis.Z {
165165 Score : float64 (processedArticle .Score ),
166166 Member : articleKey ,
167167 }).Err ()
@@ -171,14 +171,14 @@ func (fg *FeedGetter) Get(ctx context.Context, feedURI string) (*FeedResponse, e
171171
172172 // Store article in S3 if score changed
173173 if ShouldStoreArticle (oldScore , processedArticle .Score ) {
174- if err := fg .storeArticleInS3 (ctx , processedArticle ); err != nil {
174+ if err := f .storeArticleInS3 (ctx , processedArticle ); err != nil {
175175 return nil , fmt .Errorf ("failed to store article in S3: %w" , err )
176176 }
177177 }
178178 }
179179
180180 // Get all article IDs
181- articles , err := fg .getArticleIds (ctx , keys .ArticlesKey )
181+ articles , err := f .getArticleIds (ctx , keys .ArticlesKey )
182182 if err != nil {
183183 return nil , err
184184 }
@@ -194,14 +194,14 @@ func (fg *FeedGetter) Get(ctx context.Context, feedURI string) (*FeedResponse, e
194194 }, nil
195195}
196196
197- func (fg * FeedGetter ) storeArticleInS3 (ctx context.Context , article Article ) error {
197+ func (f * Fetcher ) storeArticleInS3 (ctx context.Context , article Article ) error {
198198 body , err := GenerateArticleBody (article )
199199 if err != nil {
200200 return err
201201 }
202202
203- _ , err = fg .s3Client .PutObject (ctx , & s3.PutObjectInput {
204- Bucket : aws .String (fg .s3Bucket ),
203+ _ , err = f .s3Client .PutObject (ctx , & s3.PutObjectInput {
204+ Bucket : aws .String (f .s3Bucket ),
205205 Key : aws .String (article .Hash + ".json" ),
206206 Body : bytes .NewReader ([]byte (body )),
207207 ContentType : aws .String ("application/json" ),
@@ -210,8 +210,8 @@ func (fg *FeedGetter) storeArticleInS3(ctx context.Context, article Article) err
210210 return err
211211}
212212
213- func (fg * FeedGetter ) getArticleIds (ctx context.Context , articlesKey string ) ([]string , error ) {
214- allArticles , err := fg .redisClient .ZRevRange (ctx , articlesKey , 0 , - 1 ).Result ()
213+ func (f * Fetcher ) getArticleIds (ctx context.Context , articlesKey string ) ([]string , error ) {
214+ allArticles , err := f .redisClient .ZRevRange (ctx , articlesKey , 0 , - 1 ).Result ()
215215 if err != nil {
216216 return nil , fmt .Errorf ("failed to get articles from sorted set: %w" , err )
217217 }
0 commit comments