5
GitHub - circa10a/go-mailform: A small library to send physical mail from your G...
source link: https://github.com/circa10a/go-mailform
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
go-mailform
A small library to send physical mail from your Go applications using https://mailform.io
Usage
First you will need an API Token from mailform.io
go get github.com/circa10a/go-mailform
package main
import (
"fmt"
"os"
"github.com/circa10a/go-mailform"
)
func main() {
client, err := mailform.New(&mailform.Config{
Token: "MAILFORM_API_TOKEN",
})
if err != nil {
fmt.Println(err)
}
// Create order
// You can send a PDF file via local filesystem path or a URL.
// FilePath will take precedence over URL.
order, err := client.CreateOrder(mailform.OrderInput{
// Send local pdf
FilePath: "./sample.pdf",
// Or you can send the file via URL
URL: "http://s3.amazonaws.com/some-bucket/sample.pdf",
// Shipping service options:
// FEDEX_OVERNIGHT USPS_PRIORITY_EXPRESS USPS_PRIORITY USPS_CERTIFIED_PHYSICAL_RECEIPT USPS_CERTIFIED_RECEIPT USPS_CERTIFIED USPS_FIRST_CLASS USPS_STANDARD USPS_POSTCARD
Service: "USPS_PRIORITY",
ToName: "A Name",
ToAddress1: "Address 1",
ToCity: "Seattle",
ToState: "WA",
ToPostcode: "00000",
ToCountry: "US",
FromName: "My Name",
FromAddress1: "My Address 1",
FromCity: "Dallas",
FromState: "TX",
FromPostcode: "00000",
FromCountry: "US",
})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Order ID", order.Data.ID)
// Get Order
orderDetails, err := client.GetOrder(order.Data.ID)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(orderDetails.Data)
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK