Skip to content
المشاريع

حول

حزمة SDK الرسمية من Resend للغة Go.

أدوات التطوير

كيف تُقاس هذه الأرقام

النمو المقاس للنجوم

خلال 24 ساعة
٠
خلال 7 أيام
+١
خلال 15 يومًا
+٥
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

Resend Go SDK

License: MIT Build Release Go Reference

Installation

To install the Go SDK, simply execute the following command on a terminal:

go get github.com/resend/resend-go/v4

Setup

First, you need to get an API key, which is available in the Resend Dashboard.

Example

package main

import (
    "fmt"
    "github.com/resend/resend-go/v4"
)

func main() {
    apiKey := "re_123"

    client := resend.NewClient(apiKey)

    params := &resend.SendEmailRequest{
        To:      []string{"[email protected]", "[email protected]"},
        From:    "[email protected]",
        Text:    "hello world",
        Subject: "Hello from Golang",
        Cc:      []string{"[email protected]"},
        Bcc:     []string{"[email protected]"},
        ReplyTo: "[email protected]",
    }

    sent, err := client.Emails.Send(params)
    if err != nil {
        panic(err)
    }
    fmt.Println(sent.Id)
}

Replace the placeholder API key and email addresses before sending. Use a verified domain for the From address.

You can view all the examples in the examples folder

Error handling

Use errors.As from the standard library's errors package to inspect typed API errors. HTTP 429 responses return *resend.RateLimitError; other HTTP error responses return *resend.ResendError. Handle other failures, such as network errors or canceled requests, separately:

_, err := client.Emails.Get("email-id")
if err != nil {
    var rateLimit *resend.RateLimitError
    var apiError *resend.ResendError

    switch {
    case errors.As(err, &rateLimit):
        fmt.Printf("Rate limited: %s (Retry-After: %s)\n",
            rateLimit.Message, rateLimit.RetryAfter)
    case errors.As(err, &apiError):
        fmt.Printf("Status: %d, name: %s, message: %s\n",
            apiError.StatusCode, apiError.Name, apiError.Message)
    default:
        fmt.Printf("Request failed: %v\n", err)
    }
}

ResendError.StatusCode comes from the HTTP response. If the error body cannot be read as JSON, Name is empty and Message falls back to the HTTP status. RateLimitError includes rate-limit metadata such as RetryAfter when the corresponding response headers are present. You can also detect rate limits with errors.Is(err, resend.ErrRateLimit).

The SDK does not automatically retry requests. The application decides whether and when to retry.

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…