aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-01-02 03:05:14 +0700
committerShulhan <ms@kilabit.info>2022-01-09 22:44:43 +0700
commit0e49559d0effb845c8392e00a3b860464ed88002 (patch)
tree99464987abd82d86e234a494d21b2199d2615237 /api
parent7f89b4b38ad7155a44ac7384d8c08e2dd177780c (diff)
downloadpakakeh.go-0e49559d0effb845c8392e00a3b860464ed88002.tar.xz
lib/http: refactoring NewClient to accept single struct
Previously, the NewClient function accept three parameters: serverURL, http.Header, and insecure. If we want to add another parameter, for example timeout it will cause changes on the function signature. To prevent this changes in the future, we change it now. The NewClient now accept single struct. While at it, we add option to set Timeout. The Timeout affect the http Transport Timeout and TLSHandshakeTimeout. The field is optional, if not set it will set to 10 seconds.
Diffstat (limited to 'api')
-rw-r--r--api/slack/webhook_client.go6
-rw-r--r--api/telegram/bot/bot.go6
2 files changed, 8 insertions, 4 deletions
diff --git a/api/slack/webhook_client.go b/api/slack/webhook_client.go
index 1896f9fc..e5ac2f45 100644
--- a/api/slack/webhook_client.go
+++ b/api/slack/webhook_client.go
@@ -35,9 +35,11 @@ func NewWebhookClient(webhookURL, user, channel string) (wcl *WebhookClient, err
return nil, fmt.Errorf("NewWebhookClient: %w", err)
}
- host := fmt.Sprintf("%s://%s", wurl.Scheme, wurl.Host)
+ clientOpts := &libhttp.ClientOptions{
+ ServerUrl: fmt.Sprintf("%s://%s", wurl.Scheme, wurl.Host),
+ }
wcl = &WebhookClient{
- Client: libhttp.NewClient(host, nil, false),
+ Client: libhttp.NewClient(clientOpts),
webhookPath: wurl.Path,
user: user,
channel: channel,
diff --git a/api/telegram/bot/bot.go b/api/telegram/bot/bot.go
index 844a8c25..1a5eeb97 100644
--- a/api/telegram/bot/bot.go
+++ b/api/telegram/bot/bot.go
@@ -114,10 +114,12 @@ func New(opts Options) (bot *Bot, err error) {
return nil, fmt.Errorf("bot.New: %w", err)
}
- serverURL := defURL + opts.Token + "/"
+ clientOpts := &http.ClientOptions{
+ ServerUrl: defURL + opts.Token + "/",
+ }
bot = &Bot{
opts: opts,
- client: http.NewClient(serverURL, nil, false),
+ client: http.NewClient(clientOpts),
}
fmt.Printf("Bot options: %+v\n", opts)