Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.

Commit 5500c48

Browse files
authored
Merge pull request #3 from skx/2-timeout-config
Allow user to specify a timeout.
2 parents 23de1bc + fa27545 commit 5500c48

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎rss2hook.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ type RSSEntry struct {
4141
// configuration file
4242
var Loaded []RSSEntry
4343

44+
// Timeout is the (global) timeout we use when loading remote RSS
45+
// feeds.
46+
var Timeout time.Duration
47+
4448
// loadConfig loads the named configuration file and populates our
4549
// `Loaded` list of RSS-feeds & Webhook addresses
4650
func loadConfig(filename string) {
@@ -94,7 +98,7 @@ func loadConfig(filename string) {
9498
func fetchFeed(url string) (string, error) {
9599

96100
// Ensure we setup a timeout for our fetch
97-
client := &http.Client{Timeout: time.Duration(5 * time.Second)}
101+
client := &http.Client{Timeout: Timeout}
98102

99103
// We'll only make a GET request
100104
req, err := http.NewRequest("GET", url, nil)
@@ -254,8 +258,12 @@ func main() {
254258

255259
// Parse the command-line flags
256260
config := flag.String("config", "", "The path to the configuration-file to read")
261+
timeout := flag.Duration("timeout", 5*time.Second, "The timeout used for fetching the remote feeds")
257262
flag.Parse()
258263

264+
// Setup the default timeout.
265+
Timeout = *timeout
266+
259267
if *config == "" {
260268
fmt.Printf("Please specify a configuration-file to read\n")
261269
return

0 commit comments

Comments
 (0)
⌂ 换网址