resend

package module
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 7 Imported by: 18

README

Resend Go SDK

Build Release

Installation

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

go get github.com/resendlabs/resend-go

Setup

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

Example

import "github.com/resendlabs/resend-go"

func main() {
    apiKey = "re_123"

    client := resend.NewClient(apiKey)

    params := &resend.SendEmailRequest{
        To:      []string{"to@example", "you@example.com"},
        From:    "me@exemple.io",
        Text:    "hello world",
        Subject: "Hello from Golang",
        Cc:      []string{"cc@example.com"},
        Bcc:     []string{"cc@example.com"},
        ReplyTo: "replyto@example.com",
    }

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

You can view all the examples in the examples folder

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiKey added in v1.6.0

type ApiKey struct {
	Id        string `json:"id"`
	Name      string `json:"name"`
	CreatedAt string `json:"created_at"`
}

type ApiKeysSvc added in v1.6.0

type ApiKeysSvc interface {
	Create(*CreateApiKeyRequest) (CreateApiKeyResponse, error)
	List() (ListApiKeysResponse, error)
	Remove(apiKeyId string) (bool, error)
}

type ApiKeysSvcImpl added in v1.6.0

type ApiKeysSvcImpl struct {
	// contains filtered or unexported fields
}

func (*ApiKeysSvcImpl) Create added in v1.6.0

Create creates a new API Key based on the given params https://resend.com/docs/api-reference/api-keys/create-api-key

func (*ApiKeysSvcImpl) List added in v1.6.0

List list all API Keys in the project https://resend.com/docs/api-reference/api-keys/list-api-keys

func (*ApiKeysSvcImpl) Remove added in v1.6.0

func (s *ApiKeysSvcImpl) Remove(apiKeyId string) (bool, error)

Remove deletes a given api key by id https://resend.com/docs/api-reference/api-keys/delete-api-key

type Attachment added in v1.6.0

type Attachment struct {

	// Content must be a string representation of a byte array
	Content string `json:"content,omitempty"`

	// Filename that will appear in the email.
	// Make sure you pick the correct extension otherwise preview
	// may not work as expected
	Filename string `json:"filename"`

	// Path where the attachment file is hosted
	Path string `json:"path,omitempty"`
}

type Client added in v1.6.0

type Client struct {

	// Api Key
	ApiKey string

	// Base URL
	BaseURL *url.URL

	// User agent for client
	UserAgent string

	// Services
	Emails  EmailsSvc
	ApiKeys ApiKeysSvc
	Domains DomainsSvc
	// contains filtered or unexported fields
}

Client handles communication with Resend API.

func NewClient added in v1.6.0

func NewClient(apiKey string) *Client

NewClient is the default client constructor

func NewCustomClient added in v1.6.0

func NewCustomClient(httpClient *http.Client, apiKey string) *Client

NewCustomClient builds a new Resend API client, using a provided Http client.

func (*Client) NewRequest added in v1.6.0

func (c *Client) NewRequest(method, path string, params interface{}) (*http.Request, error)

NewRequest builds and returns a new HTTP request object based on the given arguments

func (*Client) Perform added in v1.6.0

func (c *Client) Perform(req *http.Request, ret interface{}) (*http.Response, error)

Perform sends the request to the Resend API

type CreateApiKeyRequest added in v1.6.0

type CreateApiKeyRequest struct {
	Name       string `json:"name"`
	Permission string `json:"permission,omitempty"` // TODO: update permission to type
	DomainId   string `json:"domain_id,omitempty"`
}

type CreateApiKeyResponse added in v1.6.0

type CreateApiKeyResponse struct {
	Id    string `json:"id"`
	Token string `json:"token"`
}

type CreateDomainRequest added in v1.6.0

type CreateDomainRequest struct {
	Name   string `json:"name"`
	Region string `json:"region,omitempty"`
}

type CreateDomainResponse added in v1.6.0

type CreateDomainResponse struct {
	Id          string   `json:"id"`
	Name        string   `json:"name"`
	CreatedAt   string   `json:"createdAt"`
	Status      string   `json:"status"`
	Records     []Record `json:"records"`
	Region      string   `json:"region"`
	DnsProvider string   `json:"dnsProvider"`
}

type DefaultError added in v1.6.0

type DefaultError struct {
	Message string `json:"message"`
}

type Domain added in v1.6.0

type Domain struct {
	Id        string `json:"id"`
	Object    string `json:"object"`
	Name      string `json:"name"`
	CreatedAt string `json:"created_at"`
	Status    string `json:"status"`
	Region    string `json:"region"`
}

type DomainsSvc added in v1.6.0

type DomainsSvc interface {
	Create(*CreateDomainRequest) (CreateDomainResponse, error)
	Verify(domainId string) (bool, error)
	List() (ListDomainsResponse, error)
	Get(domainId string) (Domain, error)
	Remove(domainId string) (bool, error)
}

type DomainsSvcImpl added in v1.6.0

type DomainsSvcImpl struct {
	// contains filtered or unexported fields
}

func (*DomainsSvcImpl) Create added in v1.6.0

Create creates a new Domain entry based on the given params https://resend.com/docs/api-reference/domains/create-domain

func (*DomainsSvcImpl) Get added in v1.6.0

func (s *DomainsSvcImpl) Get(domainId string) (Domain, error)

Get retrieves a domain object https://resend.com/docs/api-reference/domains/get-domain

func (*DomainsSvcImpl) List added in v1.6.0

List returns the list of all doamins https://resend.com/docs/api-reference/domains/list-domains

func (*DomainsSvcImpl) Remove added in v1.6.0

func (s *DomainsSvcImpl) Remove(domainId string) (bool, error)

Remove removes a given domain entry by id https://resend.com/docs/api-reference/domains/delete-domain

func (*DomainsSvcImpl) Verify added in v1.6.0

func (s *DomainsSvcImpl) Verify(domainId string) (bool, error)

Verify verifies a given domain Id https://resend.com/docs/api-reference/domains/verify-domain

type Email added in v1.6.0

type Email struct {
	Id        string   `json:"id"`
	Object    string   `json:"obejct"`
	To        []string `json:"to"`
	From      string   `json:"from"`
	CreatedAt string   `json:"created_at"`
	Subject   string   `json:"subject"`
	Html      string   `json:"html"`
	Text      string   `json:"text"`
	Bcc       []string `json:"bcc"`
	Cc        []string `json:"cc"`
	ReplyTo   []string `json:"reply_to"`
	LastEvent string   `json:"last_event"`
}

type EmailsSvc added in v1.6.0

type EmailsSvc interface {
	Send(*SendEmailRequest) (SendEmailResponse, error)
	Get(emailId string) (Email, error)
}

type EmailsSvcImpl added in v1.6.0

type EmailsSvcImpl struct {
	// contains filtered or unexported fields
}

func (*EmailsSvcImpl) Get added in v1.6.0

func (s *EmailsSvcImpl) Get(emailId string) (Email, error)

Get retrives an email with the given emailId https://resend.com/docs/api-reference/emails/retrieve-email

func (*EmailsSvcImpl) Send added in v1.6.0

Send sends an email with the given params

type InvalidRequestError added in v1.6.0

type InvalidRequestError struct {
	StatusCode int    `json:"statusCode"`
	Name       string `json:"name"`
	Message    string `json:"message"`
}

type ListApiKeysResponse added in v1.6.0

type ListApiKeysResponse struct {
	Data []ApiKey `json:"data"`
}

type ListDomainsResponse added in v1.6.0

type ListDomainsResponse struct {
	Data []Domain `json:"data"`
}

type Record added in v1.6.0

type Record struct {
	Record   string      `json:"record"`
	Name     string      `json:"name"`
	Type     string      `json:"type"`
	Ttl      string      `json:"ttl"`
	Status   string      `json:"status"`
	Value    string      `json:"value"`
	Priority json.Number `json:"priority,omitempty"`
}

type SendEmailRequest added in v1.6.0

type SendEmailRequest struct {
	From        string       `json:"from"`
	To          []string     `json:"to"`
	Subject     string       `json:"subject"`
	Bcc         []string     `json:"bcc"`
	Cc          []string     `json:"cc"`
	ReplyTo     string       `json:"reply_to"`
	Html        string       `json:"html"`
	Text        string       `json:"text"`
	Tags        []Tag        `json:"tags"`
	Attachments []Attachment `json:"attachments"`
}

https://resend.com/docs/api-reference/emails/send-email

type SendEmailResponse added in v1.6.0

type SendEmailResponse struct {
	Id string `json:"id"`
}

type Tag added in v1.6.0

type Tag struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL