SDKs
Go
github.com/messagepipe/sdk-go: context-aware, typed, no reflection.
Install
go get github.com/messagepipe/sdk-goInitialise
import "github.com/messagepipe/sdk-go"
client := messagepipe.NewClient(messagepipe.Config{
APIKey: os.Getenv("MP_KEY"),
})Send
send, err := client.Email.Send(ctx, &messagepipe.EmailSendRequest{
To: "maya@example.com",
Subject: "Welcome!",
HTML: "<p>Glad to have you.</p>",
})
if err != nil {
return err
}
log.Printf("queued %s", send.ID)Override the idempotency key:
send, err := client.Sends.Create(ctx, req, messagepipe.WithIdempotencyKey("order:"+orderID+":confirm"))Catching errors
import "errors"
err := ...
var apiErr *messagepipe.APIError
if errors.As(err, &apiErr) {
switch apiErr.Code {
case messagepipe.ErrCreditsExhausted:
topUpCredits()
case messagepipe.ErrRateLimitExceeded:
// The SDK already backs off; this only surfaces after final retry.
default:
return err
}
}Verifying a webhook
import "github.com/messagepipe/sdk-go/webhook"
http.HandleFunc("/webhooks/mp", func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
if !webhook.Verify(body, r.Header, os.Getenv("MP_WEBHOOK_SECRET")) {
http.Error(w, "invalid signature", http.StatusBadRequest)
return
}
// handle event
})