Go SDK

A fully-typed, idiomatic client for Go.

Install

$go get github.com/usgm/usgm-go

Requires Go 1.21+.

Initialize

1package main
2
3import (
4 "os"
5
6 usgm "github.com/usgm/usgm-go"
7 usgmclient "github.com/usgm/usgm-go/client"
8 "github.com/usgm/usgm-go/option"
9)
10
11func main() {
12 client := usgmclient.NewClient(
13 option.WithApiKey(os.Getenv("USGM_API_KEY")), // never hard-code the key
14 )
15 _ = client
16}

Usage

1ctx := context.Background()
2
3// List mail
4page, err := client.Mails.List(ctx, &usgm.MailsListRequest{IsRead: usgm.Bool(false)})
5if err != nil {
6 return err
7}
8for _, mail := range page.Data {
9 fmt.Println(mail.Id, mail.Sender)
10}
11
12// Fetch one item
13mail, err := client.Mails.Get(ctx, "80421")
14
15// Mark it read
16_, err = client.Mails.Update(ctx, "80421", &usgm.UpdateMailRequest{IsRead: usgm.Bool(true)})

Error handling

1mail, err := client.Mails.Get(ctx, "does-not-exist")
2if err != nil {
3 var apiErr *usgm.Error
4 if errors.As(err, &apiErr) {
5 log.Printf("%s %d %s", apiErr.Code, apiErr.StatusCode, apiErr.RequestId)
6 }
7 return err
8}

Transient 429 and 5xx responses are retried automatically with exponential backoff. See Errors for the full problem+json contract.