Go SDK
The Go SDK uses the standard net/http package and accepts context values for cancellation.
Install
go get github.com/rahvis/email/SDK/goGo 1.21+ is supported.
Send
package main
import (
"context"
"fmt"
"log"
"os"
workonward "github.com/rahvis/email/SDK/go"
)
func main() {
client, err := workonward.NewClient(os.Getenv("WORKONWARD_API_KEY"))
if err != nil {
log.Fatal(err)
}
result, err := client.Send(context.Background(), "user@example.com", workonward.SendOptions{
Attribs: map[string]string{"first_name": "Ada"},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(result.MessageID, result.Engine)
}Batch Send
result, err := client.SendBatch(
context.Background(),
[]string{"ada@example.com", "grace@example.com"},
workonward.SendOptions{
Attribs: map[string]string{"campaign": "launch"},
},
)
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Accepted, result.MessageIDs)Options
retry := workonward.DefaultRetryConfig()
retry.MaxRetries = 2
client, err := workonward.NewClient(
os.Getenv("WORKONWARD_API_KEY"),
workonward.WithBaseURL("https://mail.gitdate.ink/api"),
workonward.WithTimeout(10*time.Second),
workonward.WithRetryConfig(retry),
workonward.WithHeader("X-Request-Source", "billing-service"),
)Error Handling
_, err := client.Send(ctx, "user@example.com", workonward.SendOptions{})
if err != nil {
switch e := err.(type) {
case *workonward.AuthenticationError:
log.Printf("API key rejected: %d", e.Code)
case *workonward.InvalidRecipientError:
log.Printf("bad recipient: %s", e.Message)
default:
log.Printf("send failed: %v", err)
}
}Each typed error includes Code, StatusCode, ResponseData, and ResponseText when available.