Retrieves a paginated list of all segments.
Methods
List
List() (ListSegmentsResponse, error)
Lists all segments using the default background context.
ListWithContext
ListWithContext(ctx context.Context) (ListSegmentsResponse, error)
Lists all segments with a custom context for cancellation and timeout control.
ListWithOptions
ListWithOptions(ctx context.Context, options *ListOptions) (ListSegmentsResponse, error)
Lists segments with pagination options.
Query Parameters
When using ListWithOptions, you can pass a ListOptions struct with the following fields:
The maximum number of segments to return per page.
The number of segments to skip before starting to return results.
Response
The object type, always list.
An array of segment objects.
The unique identifier for the segment.
The object type, always segment.
ISO 8601 timestamp of when the segment was created.
Indicates whether there are more segments available beyond the current page.
Example
package main
import (
"fmt"
"github.com/resend/resend-go/v2"
)
func main() {
client := resend.NewClient("re_123456789")
segments, err := client.Segments.List()
if err != nil {
panic(err)
}
fmt.Println("Total segments:", len(segments.Data))
for _, segment := range segments.Data {
fmt.Printf("%s: %s\n", segment.Id, segment.Name)
}
}
package main
import (
"context"
"fmt"
"github.com/resend/resend-go/v2"
)
func main() {
client := resend.NewClient("re_123456789")
options := &resend.ListOptions{
Limit: 10,
Offset: 0,
}
segments, err := client.Segments.ListWithOptions(context.Background(), options)
if err != nil {
panic(err)
}
fmt.Println("Has more:", segments.HasMore)
}