initialize paraclub-ai-mailer project with core components and configuration
This commit is contained in:
48
internal/fetcher/fetcher.go
Normal file
48
internal/fetcher/fetcher.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package fetcher
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Fetcher struct {
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func New() *Fetcher {
|
||||
return &Fetcher{
|
||||
client: &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Fetcher) FetchContent(url string) (string, error) {
|
||||
resp, err := f.client.Get(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
func (f *Fetcher) FetchAllURLs(urls []string) (map[string]string, error) {
|
||||
results := make(map[string]string)
|
||||
|
||||
for _, url := range urls {
|
||||
content, err := f.FetchContent(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
results[url] = content
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
Reference in New Issue
Block a user