apply go tools cleanup
This commit is contained in:
17
app/app.go
17
app/app.go
@ -46,7 +46,7 @@ func Run(configPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
tgram := telegram.NewTelegramSender(tgramProxy, cfg.TelegramAuthToken)
|
||||
tgram := telegram.NewSender(tgramProxy, cfg.TelegramAuthToken)
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
for i := range cfg.Feeds {
|
||||
@ -62,7 +62,7 @@ func Run(configPath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProcessFeed(feed *FeedCfg, scheduler schedule.Scheduler, dbDir string, tgram telegram.TelegramSender) {
|
||||
func ProcessFeed(feed *FeedCfg, scheduler schedule.Scheduler, dbDir string, tgram telegram.Sender) {
|
||||
log := log.WithValues("feed", feed.Name)
|
||||
sd, err := scheduler.ShouldDownload(feed.Name, feed.Cron)
|
||||
if err != nil {
|
||||
@ -82,7 +82,7 @@ func ProcessFeed(feed *FeedCfg, scheduler schedule.Scheduler, dbDir string, tgra
|
||||
}
|
||||
|
||||
var entries []parser.FeedEntry
|
||||
for _, url := range feed.Url {
|
||||
for _, url := range feed.URL {
|
||||
data, err := Download(url, feed.Proxy)
|
||||
if err != nil {
|
||||
log.Error(err, "download failed", "url", url, "proxy", feed.Proxy)
|
||||
@ -162,8 +162,8 @@ func ProcessFeed(feed *FeedCfg, scheduler schedule.Scheduler, dbDir string, tgra
|
||||
}
|
||||
}
|
||||
|
||||
func Download(url string, proxyUrl string) ([]byte, error) {
|
||||
transport, err := proxy.GetTransport(proxyUrl)
|
||||
func Download(url string, proxyURL string) ([]byte, error) {
|
||||
transport, err := proxy.GetTransport(proxyURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -172,6 +172,11 @@ func Download(url string, proxyUrl string) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
defer func() {
|
||||
err := res.Body.Close()
|
||||
if err != nil {
|
||||
log.Error(err, "Body.Close() failed")
|
||||
}
|
||||
}()
|
||||
return io.ReadAll(res.Body)
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ type FeedCfg struct {
|
||||
// Telegram instant view rhash id, see https://instantview.telegram.org/#publishing-templates
|
||||
Rhash string `yaml:"rhash" jsonschema:"default="`
|
||||
|
||||
// Feed Url, string or array of strings
|
||||
// Feed URL, string or array of strings
|
||||
// If array, all entries are merged, e.g ["https://example.com/blog/tag/foo/feed", "https://example.com/blog/tag/bar/feed" ]
|
||||
Url FeedURL `yaml:"url" jsonschema:"required,oneof_type=string;array"`
|
||||
URL FeedURL `yaml:"url" jsonschema:"required,oneof_type=string;array"`
|
||||
|
||||
// Cron expression, see https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format
|
||||
Cron string `yaml:"cron" jsonschema:"required"`
|
||||
@ -118,7 +118,7 @@ func ParseConfig(configPath string) (*Config, error) {
|
||||
if c.TelegramProxy == "" {
|
||||
c.TelegramProxy = c.Proxy
|
||||
}
|
||||
for i, _ := range c.Feeds {
|
||||
for i := range c.Feeds {
|
||||
feedCfg := &c.Feeds[i]
|
||||
if feedCfg.Proxy == "" {
|
||||
feedCfg.Proxy = c.Proxy
|
||||
@ -130,7 +130,7 @@ func ParseConfig(configPath string) (*Config, error) {
|
||||
c.TelegramProxy = ""
|
||||
}
|
||||
|
||||
for i, _ := range c.Feeds {
|
||||
for i := range c.Feeds {
|
||||
feedCfg := &c.Feeds[i]
|
||||
if feedCfg.Proxy == "NONE" {
|
||||
feedCfg.Proxy = ""
|
||||
|
Reference in New Issue
Block a user