summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-10-18 11:31:14 +0300
committerPaul Buetow <paul@buetow.org>2024-10-18 11:31:14 +0300
commitc0ffb385eaca5dbe53817ee3c288f8dcee6b414f (patch)
tree8f95d1d2ec047ef6e09c39bc4d161daa7b5456a1 /internal
parent9525b8c9a3f714235c8e591f3eddd4c05ed791da (diff)
using ctx also when posting messages
Diffstat (limited to 'internal')
-rw-r--r--internal/platforms/linkedin/linkedin.go7
-rw-r--r--internal/platforms/mastodon/mastodon.go2
2 files changed, 4 insertions, 5 deletions
diff --git a/internal/platforms/linkedin/linkedin.go b/internal/platforms/linkedin/linkedin.go
index 341834e..0f5673e 100644
--- a/internal/platforms/linkedin/linkedin.go
+++ b/internal/platforms/linkedin/linkedin.go
@@ -41,10 +41,10 @@ func post(ctx context.Context, args config.Args, sizeLimit int, ent entry.Entry)
if err != nil {
return err
}
- return callLinkedInAPI(personID, accessToken, content)
+ return callLinkedInAPI(ctx, personID, accessToken, content)
}
-func callLinkedInAPI(personID, accessToken, message string) error {
+func callLinkedInAPI(ctx context.Context, personID, accessToken, message string) error {
const url = "https://api.linkedin.com/v2/posts"
post := map[string]interface{}{
@@ -68,7 +68,7 @@ func callLinkedInAPI(personID, accessToken, message string) error {
return prompt.ErrAborted
}
- req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
+ req, err := http.NewRequestWithContext(ctx, "POST", url, bytes.NewBuffer(payload))
if err != nil {
return fmt.Errorf("Error creating request: %w", err)
}
@@ -78,7 +78,6 @@ func callLinkedInAPI(personID, accessToken, message string) error {
req.Header.Add("X-RestLi-Protocol-Version", "2.0.0")
client := &http.Client{}
- // TODO: Use ctx?
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("Error sending request: %w", err)
diff --git a/internal/platforms/mastodon/mastodon.go b/internal/platforms/mastodon/mastodon.go
index ce9a765..c5d5c35 100644
--- a/internal/platforms/mastodon/mastodon.go
+++ b/internal/platforms/mastodon/mastodon.go
@@ -31,7 +31,7 @@ func Post(ctx context.Context, args config.Args, sizeLimit int, ent entry.Entry)
return prompt.ErrAborted
}
- req, err := http.NewRequest("POST", args.Secrets.MastodonURL, bytes.NewBuffer(payloadBytes))
+ req, err := http.NewRequestWithContext(ctx, "POST", args.Secrets.MastodonURL, bytes.NewBuffer(payloadBytes))
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}