Request fields
The telnyx library uses theomitzero
semantics from the Go 1.24+ encoding/json release for request fields.
Required primitive fields (int64, string, etc.) feature the tag `json:”…,required”`. These
fields are always serialized, even their zero values.
Optional primitive types are wrapped in a param.Opt[T]. These fields can be set with the provided constructors, telnyx.String(string), telnyx.Int(int64), etc.
Any param.Opt[T], map, slice, struct or string enum uses the
tag `json:”…,omitzero”`. Its zero value is considered omitted.
The param.IsOmitted(any) function can confirm the presence of any omitzero field.
null instead of a param.Opt[T], use param.Null[T]().
To send null instead of a struct T, use param.NullStruct[T]().
.SetExtraFields(map[string]any) method which can send non-conforming
fields in the request body. Extra fields overwrite any struct fields with a matching
key. For security reasons, only use SetExtraFields with trusted data.
To send a custom value instead of a struct, use param.Override[T](https://github.com/team-telnyx/telnyx-go/tree/master/value).
Request unions
Unions are represented as a struct with fields prefixed by “Of” for each of it’s variants, only one field can be non-zero. The non-zero field will be serialized. Sub-properties of the union can be accessed via methods on the union struct. These methods return a mutable pointer to the underlying data, if present.Response objects
All fields in response structs are ordinary value types (not pointers or wrappers). Response structs also include a specialJSON field containing metadata about
each property.
.Valid() method on the JSON field.
.Valid() returns true if a field is not null, not present, or couldn’t be marshaled.
If .Valid() is false, the corresponding field will simply be its zero value.
.JSON structs also include an ExtraFields map containing
any properties in the json response that were not specified
in the struct. This can be useful for API features not yet
present in the SDK.
Response Unions
In responses, unions are represented by a flattened struct containing all possible fields from each of the object variants. To convert it to a variant use the.AsFooVariant() method or the .AsAny() method if present.
If a response value union contains primitive values, primitive fields will be alongside
the properties but prefixed with Of and feature the tag json:"...,inline".
RequestOptions
This library uses the functional options pattern. Functions defined in theoption package return a RequestOption, which is a closure that mutates a
RequestConfig. These options can be supplied to the client or at individual
requests. For example:
option.WithDebugLog(nil) may be helpful while debugging.
See the full list of request options.
Pagination
This library provides some conveniences for working with paginated list endpoints. You can use.ListAutoPaging() methods to iterate through items across all pages:
Or you can use simple .List() methods to fetch a single page and receive a standard response object
with additional helper methods like .GetNextPage(), e.g.:
File uploads
Request parameters that correspond to file uploads in multipart requests are typed asio.Reader. The contents of the io.Reader will by default be sent as a multipart form
part with the file name of “anonymous_file” and content-type of “application/octet-stream”.
The file name and content-type can be customized by implementing Name() string or ContentType() string on the run-time type of io.Reader. Note that os.File implements Name() string, so a
file returned by os.Open will be sent with the file name on disk.
We also provide a helper telnyx.File(reader io.Reader, filename string, contentType string)
which can be used to wrap any io.Reader with the appropriate file name and content type.