Documentation
¶
Index ¶
- Constants
- Variables
- func Ptr[T any](v T) *T
- func RenderDetails(details map[string]any) string
- type APIError
- type ConnectionError
- type Nullable
- type Option
- type Page
- func (p *Page[T]) All(ctx context.Context, opts ...PageOption) iter.Seq2[T, error]
- func (p *Page[T]) AppliedFilters(into any) error
- func (p *Page[T]) AutoPaging(ctx context.Context, visit func(item T) error, opts ...PageOption) error
- func (p *Page[T]) HasNext() bool
- func (p *Page[T]) NextPage(ctx context.Context) (*Page[T], error)
- type PageOption
Constants ¶
const ( // DefaultBaseURL is the production Zelf API. DefaultBaseURL = "https://api.hellozelf.com" // APIKeyEnv is read when no key is passed explicitly. APIKeyEnv = "ZELF_API_KEY" // BaseURLEnv is read when no base URL is passed explicitly. BaseURLEnv = "ZELF_BASE_URL" )
Variables ¶
var ErrBadLimit = errors.New("zelf: MaxPages and MaxItems need a value of 1 or greater")
ErrBadLimit is returned when MaxPages or MaxItems is given a value below 1.
Functions ¶
func Ptr ¶
func Ptr[T any](v T) *T
Ptr returns a pointer to v. Optional request fields are pointers, so this keeps call sites to one line: zelf.Ptr("running shoes").
func RenderDetails ¶
RenderDetails gives the field-level reasons the API sent as one readable clause, with the fields in a stable order.
Types ¶
type APIError ¶
APIError is an error response from the API. Status, Code, and LogID come straight from the response envelope.
type ConnectionError ¶
type ConnectionError struct{ Err error }
ConnectionError wraps a transport failure: the request never produced an HTTP response.
func (*ConnectionError) Error ¶
func (e *ConnectionError) Error() string
func (*ConnectionError) Unwrap ¶
func (e *ConnectionError) Unwrap() error
type Nullable ¶
Nullable is a field that can carry a value, carry JSON null, or be left out of the request entirely. The generated types use it wherever the API treats those three as different, so it is re-exported here and a caller never needs to import the generator's own dependency.
type Option ¶
type Option func(*config)
Option configures a Client.
func WithAPIKey ¶
WithAPIKey sets the brand API key. Without it the ZELF_API_KEY environment variable is used.
func WithBaseURL ¶
WithBaseURL points the client at a different deployment.
func WithHTTPClient ¶
WithHTTPClient supplies the http.Client used for transport.
func WithHeader ¶
WithHeader adds a header to every request.
func WithMaxRetries ¶
WithMaxRetries sets how many times a retryable response is retried.
func WithRetryWrites ¶
WithRetryWrites allows non-idempotent requests to be retried. The API publishes no idempotency key, so a retried create can run twice. Opt in only when the caller can tolerate that.
func WithTimeout ¶
WithTimeout bounds each individual HTTP attempt.
type Page ¶
type Page[T any] struct { Results []T LogID string Page int ItemCount int Next *int Previous *int // contains filtered or unexported fields }
Page holds one page of results plus the envelope metadata that came with it.
func (*Page[T]) All ¶
All ranges over the remaining items, yielding the error that ended the walk as the second value. Stop early by breaking out of the loop.
for item, err := range page.All(ctx, zelf.MaxItems(100)) {
if err != nil { return err }
...
}
func (*Page[T]) AppliedFilters ¶
AppliedFilters decodes the effective filters the API reports back, which explains an empty result set.
func (*Page[T]) AutoPaging ¶
func (p *Page[T]) AutoPaging(ctx context.Context, visit func(item T) error, opts ...PageOption) error
AutoPaging walks the remaining pages and calls visit for each item. Returning an error from visit stops the walk and surfaces that error. MaxPages and MaxItems bound how far it goes.
type PageOption ¶
type PageOption func(*pageLimits)
PageOption bounds how far a walk over the remaining pages goes.
func MaxItems ¶
func MaxItems(n int) PageOption
MaxItems stops the walk once n items have been visited, so no page is requested that is not needed to reach n.
func MaxPages ¶
func MaxPages(n int) PageOption
MaxPages stops the walk after n pages, counting the one already in hand. A value of 1 makes no further request.