sdk

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 6 Imported by: 1 module, 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

Overview

Package sdk provides classified errors and resumable pages for the product SDKs.

Error reports failures through Reason and preserves underlying errors for errors.Is and errors.As. Page carries results and an opaque Cursor. Product clients own the query and connection used by Page.Next.

Resuming a list

After consuming a page, persist page.Cursor.String(). To resume, recreate the original request and use the same account. Here list is the original product list operation, and request contains its original query options:

resume, err := sdk.ParseCursor(saved)
if err != nil {
	return err
}
if resume.IsZero() {
	return nil // The saved page was the last batch.
}
request.Cursor = resume
page, err = list(ctx, request)

Keep every original query option; a mismatch returns InvalidArgument before a content request. An empty cursor starts a fresh query. During a live iteration, page.Next(ctx) keeps the client and query bound. JSON-decoded pages retain data and cursors; resume them through the list operation to restore that binding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor struct {
	// contains filtered or unexported fields
}

Cursor holds an opaque continuation received from a product SDK. Its zero value starts a query or marks the last page. Persist String and parse it with ParseCursor, then pass the result in the original query's Cursor field. Product operations validate the query and account binding before sending a content request. Cursors contain no credentials and provide no cryptographic authenticity.

func ParseCursor

func ParseCursor(text string) (Cursor, error)

ParseCursor checks the text encoding. The receiving product operation checks the envelope, version, and query binding. Empty text returns the zero cursor.

func (Cursor) IsZero

func (c Cursor) IsZero() bool

IsZero reports whether there is no continuation.

func (Cursor) MarshalText

func (c Cursor) MarshalText() ([]byte, error)

MarshalText encodes the cursor, including the empty last-page cursor.

func (Cursor) String

func (c Cursor) String() string

String returns the persistent text form; the zero cursor returns "".

func (*Cursor) UnmarshalJSON

func (c *Cursor) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts the persistent JSON string form, including "" for the zero cursor. Other JSON values return InvalidArgument and leave c unchanged.

func (*Cursor) UnmarshalText

func (c *Cursor) UnmarshalText(text []byte) error

UnmarshalText parses the persistent text form, leaving c unchanged on failure.

type Error

type Error struct {
	Reason     Reason
	Operation  string
	Message    string
	HTTPStatus int            // Zero when no HTTP response was received.
	RetryAfter *time.Duration // Present only when the upstream supplied a valid Retry-After.
	Err        error          `json:"-"` // Inspect with Unwrap; causes are excluded from JSON diagnostics.
}

Error records an SDK failure. Operation and Message contain controlled text; Err preserves its cause and must be safe to expose through Unwrap. Product implementations classify external errors before attaching them. Formatting prints the summary only, including with %#v; inspect Unwrap to retrieve the cause. Match Reason with ReasonOf or errors.Is.

func (*Error) Error

func (e *Error) Error() string

Error returns the classification and controlled summary, without the cause.

func (*Error) Format added in v1.4.0

func (e *Error) Format(state fmt.State, verb rune)

Format keeps the cause out of formatted diagnostics, including %#v.

func (*Error) Is

func (e *Error) Is(target error) bool

Is matches a nonempty Reason on another Error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error, including context cancellation or a persistence failure when applicable.

type Page

type Page[T any] struct {
	Items  []T    `json:"items"`  // Current batch; SDK-created pages use a non-nil slice.
	Cursor Cursor `json:"cursor"` // Continuation after Items; zero marks the last batch.
	// contains filtered or unexported fields
}

Page carries one batch and a cursor for the following batch. Next uses the client and original query captured by the product operation. A JSON-decoded page has no such binding; restore its Cursor through the product operation.

To walk a live query, process Items, stop when Cursor.IsZero(), and otherwise call Next(ctx). To resume later, save Cursor.String(), call ParseCursor on that string, and set the original list request's Cursor to the parsed value. Repeat the original query options and account; changing them is InvalidArgument. Cursors resume live upstream data, so they do not provide a snapshot.

func NewPage added in v1.4.0

func NewPage[T any](items []T, cursor Cursor, load func(context.Context) (Page[T], error)) Page[T]

NewPage binds a batch to the product's continuation operation. SDK product packages use it to capture their client and original query without exposing either in JSON. A nil loader leaves the page unbound. Nil items become [].

func (Page[T]) Next

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

Next fetches the following batch with ctx. The last page returns an empty page without network I/O. A nonterminal unbound page returns InvalidArgument.

func (*Page[T]) UnmarshalJSON added in v1.4.0

func (p *Page[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the data and clears any prior client/query binding.

type Reason

type Reason string

Reason identifies the category of an SDK failure.

const (
	// InvalidArgument reports an invalid input, mismatched cursor, or unbound object.
	InvalidArgument Reason = "invalid_argument"
	// Unauthorized reports missing or rejected authentication.
	Unauthorized Reason = "unauthorized"
	// CredentialsExpired reports credentials requiring renewal or login.
	CredentialsExpired Reason = "credentials_expired"
	// Forbidden reports an upstream access restriction.
	Forbidden Reason = "forbidden"
	// NotFound reports an upstream object that does not exist.
	NotFound Reason = "not_found"
	// ContentUnavailable reports content that the upstream cannot provide.
	ContentUnavailable Reason = "content_unavailable"
	// ChallengeRequired reports an unresolved browser challenge.
	ChallengeRequired Reason = "challenge_required"
	// RateLimited reports an upstream request limit.
	RateLimited Reason = "rate_limited"
	// UpstreamError reports an upstream operation failure.
	UpstreamError Reason = "upstream_error"
	// UpstreamUnavailable reports an unavailable upstream or transport.
	UpstreamUnavailable Reason = "upstream_unavailable"
	// MalformedUpstreamResponse reports an invalid upstream response.
	MalformedUpstreamResponse Reason = "malformed_upstream_response"
	// ResourceForbidden reports a resource outside the product's allowed origins.
	ResourceForbidden Reason = "resource_forbidden"
	// LocalStateError reports a credential read, save, or other local state failure.
	LocalStateError Reason = "local_state_error"
)

func ReasonOf

func ReasonOf(err error) Reason

ReasonOf returns the first SDK classification in err's chain, or "".

Directories

Path Synopsis
Package ascii2d searches uploaded image bytes using color and feature matching.
Package ascii2d searches uploaded image bytes using color and feature matching.
Package download saves selected Pixiv artwork pages with filename templates.
Package download saves selected Pixiv artwork pages with filename templates.
Package fanbox provides a read-only FANBOX client bound to one session.
Package fanbox provides a read-only FANBOX client bound to one session.
internal/api
Package api owns FANBOX session headers, identity parsing, redirects, and challenge recovery through the shared Chrome TLS and FlareSolverr client.
Package api owns FANBOX session headers, identity parsing, redirects, and challenge recovery through the shared Chrome TLS and FlareSolverr client.
internal
cloudflare
Package cloudflare shares Chrome TLS transport and FlareSolverr clearance acquisition between product SDKs.
Package cloudflare shares Chrome TLS transport and FlareSolverr clearance acquisition between product SDKs.
cursor
Package cursor encodes query-bound continuations for the product SDKs.
Package cursor encodes query-bound continuations for the product SDKs.
Package pixiv provides an account-bound client for the Pixiv App API.
Package pixiv provides an account-bound client for the Pixiv App API.
internal/api
Package api owns Pixiv App transport, media URL policy, and sanitized failures.
Package api owns Pixiv App transport, media URL policy, and sanitized failures.
internal/api/oauth
Package oauth exchanges Pixiv App tokens and generates PKCE login material.
Package oauth exchanges Pixiv App tokens and generates PKCE login material.
Package saucenao searches SauceNAO using caller-supplied image bytes and an API key.
Package saucenao searches SauceNAO using caller-supplied image bytes and an API key.

Jump to

Keyboard shortcuts

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