MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / SubscribeToList

Function SubscribeToList

server-source-code/internal/handler/marketing.go:36–62  ·  view source on GitHub ↗

SubscribeToList POSTs name+email to the configured Listmonk public list URL. Returns nil on 2xx, a wrapped error otherwise.

(ctx context.Context, name, email string)

Source from the content-addressed store, hash-verified

34// SubscribeToList POSTs name+email to the configured Listmonk public list URL.
35// Returns nil on 2xx, a wrapped error otherwise.
36func SubscribeToList(ctx context.Context, name, email string) error {
37 form := url.Values{}
38 form.Set("NAME", name)
39 form.Set("EMAIL", email)
40 form.Set(honeypotField, "")
41
42 req, err := http.NewRequestWithContext(ctx, http.MethodPost, marketingSubscribeURL, strings.NewReader(form.Encode()))
43 if err != nil {
44 return fmt.Errorf("build request: %w", err)
45 }
46 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
47
48 client := &http.Client{Timeout: 10 * time.Second}
49 resp, err := client.Do(req)
50 if err != nil {
51 return fmt.Errorf("post to marketing list: %w", err)
52 }
53 defer func() {
54 _, _ = io.Copy(io.Discard, resp.Body)
55 _ = resp.Body.Close()
56 }()
57
58 if resp.StatusCode < 200 || resp.StatusCode >= 300 {
59 return fmt.Errorf("marketing list returned status %d", resp.StatusCode)
60 }
61 return nil
62}
63
64// AutoSubscribeIfHosted enrolls a freshly-created user in the newsletter when
65// the instance is running in admin_mode (managed/SaaS deployments). On

Callers 3

SubscribeNewsletterMethod · 0.85
AutoSubscribeIfHostedFunction · 0.85
SubscribeMethod · 0.85

Calls 2

SetMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected