-
Notifications
You must be signed in to change notification settings - Fork 1
/
rss_feed_request.go
41 lines (33 loc) · 1.14 KB
/
rss_feed_request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package utils
import (
"encoding/json"
"github.com/Crossbell-Box/OperatorSync/app/worker/global"
commonConsts "github.com/Crossbell-Box/OperatorSync/common/consts"
commonTypes "github.com/Crossbell-Box/OperatorSync/common/types"
"github.com/mmcdole/gofeed"
)
func RSSFeedRequest(url string, withProxy bool) (*gofeed.Feed, uint, error) {
feedsBody, err := HttpRequest(url, withProxy)
if err != nil {
return nil, commonConsts.ERROR_CODE_HTTP_REQUEST_FAILED, err
}
fp := gofeed.NewParser()
feed, err := fp.ParseString(string(feedsBody))
if err != nil {
return nil, commonConsts.ERROR_CODE_FAILED_TO_PARSE_FEEDS, err
}
return feed, 0, nil
}
func RSSFeedRequestJson(url string, withProxy bool) (*commonTypes.FeedWithExtra, uint, error) {
feedsBody, err := HttpRequest(url, withProxy)
if err != nil {
return nil, commonConsts.ERROR_CODE_HTTP_REQUEST_FAILED, err
}
var feed commonTypes.FeedWithExtra
err = json.Unmarshal(feedsBody, &feed)
if err != nil {
global.Logger.Errorf("Failed to parse response %s as json with error: %v", feedsBody, err)
return nil, commonConsts.ERROR_CODE_FAILED_TO_PARSE_FEEDS, err
}
return &feed, 0, nil
}