Documentation
¶
Overview ¶
Package zerodrop provides disposable email inboxes for testing auth flows in CI pipelines. OTPs and magic links are auto-extracted at Cloudflare's edge — no regex, no Docker, no signup.
Basic usage:
client := zerodrop.New() inbox := client.GenerateInbox() email, err := client.WaitForLatest(ctx, inbox, nil) fmt.Println(email.OTP) // "847291" — auto-extracted fmt.Println(email.MagicLink) // "https://..." — auto-extracted
Example ¶
package main
import (
"context"
"fmt"
"time"
zerodrop "github.com/zerodrop-dev/zerodrop-go"
)
func main() {
client := zerodrop.New()
inbox := client.GenerateInbox()
// Trigger your app's email flow with the inbox address...
ctx := context.Background()
email, err := client.WaitForLatest(ctx, inbox, &zerodrop.Options{
Timeout: 15 * time.Second,
})
if err != nil {
fmt.Println("no email:", err)
return
}
fmt.Println(email.OTP) // auto-extracted
fmt.Println(email.MagicLink) // auto-extracted
}
Output:
Example (Filter) ¶
package main
import (
"context"
"time"
zerodrop "github.com/zerodrop-dev/zerodrop-go"
)
func main() {
client := zerodrop.New()
inbox := client.GenerateInbox()
ctx := context.Background()
email, _ := client.WaitForLatest(ctx, inbox, &zerodrop.Options{
Timeout: 15 * time.Second,
Filter: &zerodrop.Filter{
From: "noreply@yourapp.com",
HasOTP: zerodrop.Bool(true),
},
})
_ = email
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
ErrUnauthorized is returned when an invalid API key is provided.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the ZeroDrop API client.
func New ¶
func New(opts ...ClientOption) *Client
New creates a ZeroDrop client. With no options it runs in free sandbox mode — shared domain, 30-minute TTL, no signup required.
func (*Client) FetchLatest ¶
FetchLatest returns the newest email matching the filter, or nil if the inbox is empty or nothing matches.
func (*Client) GenerateInbox ¶
GenerateInbox returns a ready-to-use email address instantly. No network request is made.
func (*Client) WaitForLatest ¶
WaitForLatest blocks until an email matching the filter arrives, using SSE for sub-second delivery with a polling fallback. It returns a TimeoutError if nothing arrives within the timeout.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client.
func WithAPIKey ¶
func WithAPIKey(key string) ClientOption
WithAPIKey sets a Workspace API key. Omit for free sandbox mode.
func WithBaseURL ¶
func WithBaseURL(url string) ClientOption
WithBaseURL points the client at a self-hosted instance.
func WithHTTPClient ¶
func WithHTTPClient(h *http.Client) ClientOption
WithHTTPClient sets a custom *http.Client.
type Email ¶
type Email struct {
ID string `json:"id"`
From string `json:"from"`
To string `json:"to"`
Subject string `json:"subject"`
Body string `json:"body"`
RawBody string `json:"rawBody"`
ReceivedAt time.Time `json:"receivedAt"`
// OTP is the auto-extracted 4-8 digit verification code.
// Empty string if not detected.
OTP string `json:"otp"`
// MagicLink is the auto-extracted verification/reset URL.
// Empty string if not detected.
MagicLink string `json:"magicLink"`
}
Email represents a caught email with auto-extracted fields.
type Filter ¶
type Filter struct {
// From matches the sender address.
From string
// Subject matches the subject line.
Subject string
// Body matches the email body.
Body string
// HasOTP, when non-nil, requires (or excludes) an extracted OTP.
HasOTP *bool
// HasMagicLink, when non-nil, requires (or excludes) a magic link.
HasMagicLink *bool
}
Filter narrows which email WaitForLatest and FetchLatest return. All string matches are case-insensitive partial matches.
type NetworkError ¶
type NetworkError struct {
Err error
}
NetworkError wraps transport-level failures.
func (*NetworkError) Error ¶
func (e *NetworkError) Error() string
func (*NetworkError) Unwrap ¶
func (e *NetworkError) Unwrap() error
type Options ¶
type Options struct {
// Timeout is the total time to wait. Defaults to 10s.
Timeout time.Duration
// PollInterval is the delay between polls. Defaults to 2s.
PollInterval time.Duration
// DisableSSE forces polling mode. By default SSE is used
// for sub-second delivery with automatic polling fallback.
DisableSSE bool
// Filter narrows which email is returned.
Filter *Filter
}
Options configures WaitForLatest.
type TimeoutError ¶
TimeoutError is returned when no email arrives within the timeout.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string