zelf

package
v0.0.0-...-e8d770c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

View Source
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

func RenderDetails(details map[string]any) string

RenderDetails gives the field-level reasons the API sent as one readable clause, with the fields in a stable order.

Types

type APIError

type APIError struct {
	Status  int
	Code    string
	Message string
	Details map[string]any
	LogID   string
}

APIError is an error response from the API. Status, Code, and LogID come straight from the response envelope.

func (*APIError) Error

func (e *APIError) Error() string

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

type Nullable[T any] = nullable.Nullable[T]

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.

func Null

func Null[T any]() Nullable[T]

Null sends JSON null for a Nullable field, which is not the same as leaving the field out: zelf.Null[string]().

func Value

func Value[T any](v T) Nullable[T]

Value fills a Nullable field: zelf.Value("running shoes").

type Option

type Option func(*config)

Option configures a Client.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the brand API key. Without it the ZELF_API_KEY environment variable is used.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL points the client at a different deployment.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient supplies the http.Client used for transport.

func WithHeader

func WithHeader(name, value string) Option

WithHeader adds a header to every request.

func WithMaxRetries

func WithMaxRetries(n int) Option

WithMaxRetries sets how many times a retryable response is retried.

func WithRetryWrites

func WithRetryWrites(enabled bool) Option

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

func WithTimeout(d time.Duration) Option

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

func (p *Page[T]) All(ctx context.Context, opts ...PageOption) iter.Seq2[T, error]

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

func (p *Page[T]) AppliedFilters(into any) error

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.

func (*Page[T]) HasNext

func (p *Page[T]) HasNext() bool

HasNext reports whether another page is available.

func (*Page[T]) NextPage

func (p *Page[T]) NextPage(ctx context.Context) (*Page[T], error)

NextPage fetches the page after this one, or returns nil when there is none.

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.

Directories

Path Synopsis
internal
Package webhooks verifies the signature Zelf puts on every webhook delivery.
Package webhooks verifies the signature Zelf puts on every webhook delivery.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL