Go
Changelog
Every release of the package, newest first.
0.0.1
The first release of the Go SDK: the module github.com/bfzli/nextmail-go, with the package nextmail. It needs Go 1.24 or later and nothing outside the standard library. It has a method for each of the 684 methods of the TypeScript SDK, in the same 53 namespaces and under the same names in Go’s casing, as fields of the client: client.Emails.Send, client.Threads.List, client.Domains.Verify. They cover everything from sending and reading mail to contacts, broadcasts, automations, the calendar, booking pages, tasks and the settings of a workspace, and a parity check proves that each one sends the same request as its TypeScript twin.
nextmail.New()readsNEXTMAIL_API_KEY,NEXTMAIL_ACCESS_TOKENandNEXTMAIL_BASE_URL, and takesWithAPIKey,WithAccessToken,WithAccessTokenFunc,WithBaseURL,WithHTTPClient,WithTimeout,WithMaxRetries,WithUserAgentandWithHeader. It never fails: a missing or malformed credential is reported byclient.Err()and by the first call.- Every method takes a
context.Contextfirst, which cancels the call or gives it a deadline. Request bodies arenextmail.Bodymaps that keep the field names of the API, options are functions such asnextmail.WithLimitandnextmail.WithCursor, and results arenextmail.Objectvalues with readers such asString,Int,Bool,TimeandObject. - Every paginated resource has
Listfor one page,ListAllfor every item as a slice, andIterate, which fetches the next page only when it gets there. Range over itsAll(), or callNext,ItemandErrin a plain loop. - Failures come back as
*nextmail.Errorvalues withStatus,Type,Code,Param,DocURL,RequestID,RetryAfter,FieldsandBody, anderrors.Ismatches them against sentinels such asErrNotFound,ErrValidation,ErrRateLimited,ErrStepUpRequired,ErrNetworkandErrTimeout. A mistake in the call itself matchesErrInvalidArgumentand is returned before anything is sent. - Reads, sends and every write that is safe to repeat are retried on 408, 500, 502, 503 and 504 with backoff, and on a 429 only when its
Retry-Afteris a minute or less. Every send carries an idempotency key that its retries reuse, andnextmail.WithIdempotencyKeysets your own. - An OAuth access token works in place of an API key, given as it is or by a function that runs before every request, so the token can be renewed without a new client. When a change made with a token needs a verification code, the error matches
ErrStepUpRequired, andclient.Security.BeginStepUpandVerifyStepUpprovide one. nextmail.VerifyWebhookSignaturechecks a webhook delivery in constant time, refuses one more than five minutes old and returns the event.nextmail.NewTempMailbuilds a client for disposable inboxes that needs no credential, andclient.Requestcalls an endpoint no method wraps, with the credential, timeout and retries of the client.nextmail.ResolveLanguage,LanguageByCode,IsRTLLanguage,IsAPIKey,IsAccessTokenandIsSealedare the helpers of the TypeScript SDK, and theconstantspackage holds the sets of values the API uses, such as webhook events, scopes and statuses.- A client is safe for concurrent use. It sends a credential over plain
http:only to a server on this machine, its default HTTP client follows no redirects, and printing a client, an option or an error never shows a credential.
Google Workspace