Go SDK

The Goomzo API for Go.

github.com/goomzo/goomzo-go is the Goomzo API for Go. It types every request and answer, retries safely within your context's deadline, and pages through lists for you. It needs nothing beyond the standard library.

Requirements

Install

go get github.com/goomzo/goomzo-go

Make your first request

Set your API key's secret as GOOMZO_API_KEY, then send a message:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/goomzo/goomzo-go"
)

func main() {
	client, err := goomzo.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	msg, err := client.Messages.SendOne(context.Background(), goomzo.MessageInput{
		To:      "+255712345678",
		Channel: goomzo.SMS,
		Content: &goomzo.Content{Text: "Amina, order #1042 is ready."},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(msg.ID, msg.Status)
}

How it reads

  • Every call takes a context. Cancel it, or give it a deadline, to stop a call and its retries.
  • Requests and answers are structs, with the API's fields. A field that can be empty in an answer is a pointer, such as Message.Error.
  • Lists are iterators. Range over one for every item, or ask for one page.

What it does for you

  • A fixed version: it pins the API version it was written for, so a new version never changes what your code gets.
  • Safe retries: network errors, 429 and 5xx are tried again, twice by default. Every POST carries an Idempotency-Key, the same on each try, so nothing is done twice.
  • Errors you can act on: an *APIError has the Status, the Code, the Fields that were wrong and the RequestID.

Next steps

Last updated