Skip to content

Commit

Permalink
Implemented mrusme#1 for Hacker News
Browse files Browse the repository at this point in the history
  • Loading branch information
mrusme committed Jan 11, 2023
1 parent 60a5162 commit 4f1208b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion system/hackernews/hackernews.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"strconv"
"time"

Expand Down Expand Up @@ -97,7 +99,29 @@ func (sys *System) Description() string {
}

func (sys *System) Load() error {
sys.client = hn.NewClient()
var httpClient *http.Client = nil
var httpTransport *http.Transport = nil

proxy := sys.config["proxy"].(string)
if proxy != "" {
proxyURL, err := url.Parse(proxy)
if err != nil {
sys.logger.Error(err)
} else {
sys.logger.Debugf("setting up http proxy transport: %s\n",
proxyURL.String())
httpTransport = &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
}
}

httpClient = &http.Client{
Transport: httpTransport,
Timeout: time.Second * 10,
}

sys.client = hn.NewClient(hn.WithHTTPClient(httpClient))
return nil
}

Expand Down

0 comments on commit 4f1208b

Please sign in to comment.