idempotencyrpc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package idempotencyrpc provides method-aware durable JSON-RPC invocation ownership and bounded response or protocol-error replay.

Index

Constants

View Source
const (
	// MaxResponseBytes is the largest persisted JSON-RPC response envelope.
	MaxResponseBytes = 900 * 1024
	// MinResponseBytes leaves room for a durable internal-error response.
	MinResponseBytes = 256
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CallResult

type CallResult struct {
	Outcome  idempotency.Outcome
	Response Response
	Replayed bool
}

CallResult reports the semantic outcome and any handler response.

type Error

type Error struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

Error is a JSON-RPC protocol error that can be durably replayed.

type FingerprintFunc

type FingerprintFunc func(Request) (idempotency.Fingerprint, error)

FingerprintFunc computes canonical business-request identity.

type Handler

type Handler func(context.Context, Request) Response

Handler executes one elected JSON-RPC request owner.

type KeyFunc

type KeyFunc func(context.Context, Request) (idempotency.Key, error)

KeyFunc constructs a caller and method-scoped key.

type Middleware

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

Middleware durably elects handlers and replays bounded responses.

func New

func New(options Options) (*Middleware, error)

New validates options and constructs JSON-RPC middleware.

func (*Middleware) Call

func (m *Middleware) Call(
	ctx context.Context,
	request Request,
	handler Handler,
) (result CallResult, err error)

Call invokes handler only for a newly acquired or taken-over request.

type Options

type Options struct {
	Service           *idempotency.Service
	Lease             time.Duration
	MaxResponseBytes  int
	TransitionTimeout time.Duration
	Key               KeyFunc
	Fingerprint       FingerprintFunc
}

Options configures method-aware durable JSON-RPC invocation.

type Request

type Request struct {
	Method string
	Params json.RawMessage
}

Request contains the business fields used for method-aware idempotency.

type Response

type Response struct {
	Result json.RawMessage `json:"result,omitempty"`
	Error  *Error          `json:"error,omitempty"`
}

Response contains exactly one JSON result or protocol error.

Jump to

Keyboard shortcuts

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