Go SDK
Send email with Gorilla/mux
Use Parcel Wing from Gorilla/mux handlers in Go HTTP services.
Install the SDK
The official Go SDK is published as github.com/parcelwing/parcelwing-go.
Terminal
go get github.com/parcelwing/parcelwing-go
Gorilla/mux handler
Create the Parcel Wing client during server startup, then reuse it from trusted server-side handlers.
main.go
package mainimport ("encoding/json""net/http""os""github.com/gorilla/mux"parcelwing "github.com/parcelwing/parcelwing-go")func main() {client, err := parcelwing.New(os.Getenv("PARCELWING_API_KEY"))if err != nil {panic(err)}r := mux.NewRouter()r.HandleFunc("/send-welcome", func(w http.ResponseWriter, r *http.Request) {var payload map[string]stringif err := json.NewDecoder(r.Body).Decode(&payload); err != nil {http.Error(w, "invalid json", http.StatusBadRequest)return}emails, err := client.Emails.Send(r.Context(), parcelwing.EmailSendRequest{From: os.Getenv("PARCELWING_FROM_EMAIL"),To: payload["email"],TemplateAlias: "welcome",TemplateParams: map[string]any{"first_name": payload["first_name"]},})if err != nil {http.Error(w, err.Error(), http.StatusBadGateway)return}w.Header().Set("content-type", "application/json")json.NewEncoder(w).Encode(map[string]any{"id": emails[0].ID})}).Methods(http.MethodPost)http.ListenAndServe(":8080", r)}
Production notes
- Keep
PARCELWING_API_KEYin server-side environment variables. - Use the incoming request context where available so sends can respect request cancellation.
- Log structured
*parcelwing.Errorfields for support and debugging.