Configuration
Set up the client with your API key, retries and timeouts.
The client reads its settings once, when you make it. Make one and share it: it's safe to use from many goroutines.
Options
client, err := goomzo.NewClient(
goomzo.WithAPIKey(os.Getenv("GOOMZO_API_KEY")),
goomzo.WithMaxRetries(2),
goomzo.WithTimeout(60*time.Second),
)| Option | Description | Default |
|---|---|---|
WithAPIKey | Your API key's secret. | GOOMZO_API_KEY |
WithMaxRetries | How many times a failed request is tried again. | 2 |
WithTimeout | How long to wait for each try. | 60s |
WithBaseURL | Where the API is. | https://api.goomzo.africa |
WithHTTPClient | Your own *http.Client, such as for a proxy or tests. | http.DefaultClient |
Important: Keep the API key on your server. Never put it in code that runs in a browser or an app.
Contexts
Every call takes a context.Context. Its deadline covers the call and every retry:
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
msg, err := client.Messages.Get(ctx, "msg_7c1x9v2b4n6m8q0w")Idempotency keys
Every call that creates something takes WithIdempotencyKey, so a retry from your side isn't done twice. Left out,
one is made for each call.
client.Messages.SendOne(ctx, goomzo.MessageInput{
To: "+255712345678",
Channel: goomzo.SMS,
Content: &goomzo.Content{Text: "Your order is ready."},
}, goomzo.WithIdempotencyKey("order-1042-ready"))API version
The SDK sends the Goomzo-Version it was written for, as goomzo.APIVersion.
Next steps
Last updated