adapter

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MPL-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_MESSAGE_SIZE = 1 * 1024 * 1024 // 1MB

Variables

This section is empty.

Functions

func IsHTTPRetryableError added in v0.5.0

func IsHTTPRetryableError(err error) bool

IsHTTPRetryableError determines if an error is retryable for HTTP requests

Types

type Base64

type Base64 interface {
	Encode(data []byte) string
	Decode(data string) ([]byte, error)
}

Base64 defines an interface for Base64 operations to enable mocking

func NewBase64

func NewBase64() Base64

type ChromedpClient added in v0.5.0

type ChromedpClient interface {
	NewExecAllocator(ctx context.Context, opts []chromedp.ExecAllocatorOption) (context.Context, context.CancelFunc)
	NewContext(ctx context.Context) (context.Context, context.CancelFunc)
	Run(ctx context.Context, actions ...chromedp.Action) error
	Navigate(url string) chromedp.NavigateAction
	WaitReady(sel string, waitReadyOpts ...chromedp.QueryOption) chromedp.QueryAction
	Sleep(duration time.Duration) chromedp.Action
	EmulateViewport(width, height int64) chromedp.EmulateAction
	FullScreenshot(result *[]byte, quality int) chromedp.Action
	Evaluate(expr string, result interface{}, options ...chromedp.EvaluateOption) chromedp.EvaluateAction
}

ChromedpClient defines an interface for chromedp operations to enable mocking

func NewChromedpClient added in v0.5.0

func NewChromedpClient() ChromedpClient

type Clock

type Clock interface {
	Now() time.Time
	Since(t time.Time) time.Duration
	Sleep(d time.Duration)
	Parse(layout, value string) (time.Time, error)
	Unix(sec int64, nsec int64) time.Time
	After(d time.Duration) <-chan time.Time
	NewTicker(d time.Duration) *time.Ticker
}

Clock defines an interface for time operations to enable mocking

func NewClock

func NewClock() Clock

NewClock creates a new real clock implementation

type CloudflareClient

type CloudflareClient interface {
	// UploadImage uploads a single image to Cloudflare Images
	UploadImage(ctx context.Context, rc *cloudflare.ResourceContainer, params cloudflare.UploadImageParams) (cloudflare.Image, error)

	// GetImage gets the details of an uploaded image, including variant URLs
	GetImage(ctx context.Context, rc *cloudflare.ResourceContainer, id string) (cloudflare.Image, error)

	// UploadVideoFromURL uploads a video to Cloudflare Stream via URL
	UploadVideoFromURL(ctx context.Context, params cloudflare.StreamUploadFromURLParameters) (cloudflare.StreamVideo, error)

	// UploadVideoFromFile uploads a video to Cloudflare Stream from a file path
	UploadVideoFromFile(ctx context.Context, params cloudflare.StreamUploadFileParameters) (cloudflare.StreamVideo, error)

	// GetVideo retrieves video details from Cloudflare Stream
	GetVideo(ctx context.Context, params cloudflare.StreamParameters) (cloudflare.StreamVideo, error)
}

CloudflareClient defines an interface for Cloudflare Images and Stream API operations to enable mocking

func NewCloudflareClient

func NewCloudflareClient(apiToken string) (CloudflareClient, error)

NewCloudflareClient creates a new real Cloudflare client

type EthClient

type EthClient interface {
	// SubscribeFilterLogs subscribes to filter logs
	SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

	// FilterLogs retrieves logs that match the filter query
	FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)

	// BlockByNumber returns a block by number
	BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)

	// HeaderByNumber returns a header by number
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

	// CallContract calls a contract function
	CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

	// CodeAt returns the code of the given account at the given block number
	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)

	// TransactionReceipt returns the receipt of a transaction by transaction hash
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

	// TransactionSender returns the sender address of a transaction
	TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)

	// Close closes the connection
	Close()
}

EthClient defines an interface for Ethereum client operations to enable mocking

type EthClientDialer

type EthClientDialer interface {
	Dial(ctx context.Context, rawurl string) (EthClient, error)
}

EthClientDialer defines an interface for dialing Ethereum clients

func NewEthClientDialer

func NewEthClientDialer() EthClientDialer

NewEthClientDialer creates a new real Ethereum client dialer

type FileSystem

type FileSystem interface {
	// Create creates a file
	Create(name string) (*os.File, error)

	// CreateTemp creates a temporary file
	CreateTemp(dir, pattern string) (*os.File, error)

	// Remove removes a file
	Remove(name string) error

	// WriteFile writes data to a file
	WriteFile(file *os.File, data []byte) (int, error)

	// Close closes a file
	Close(file *os.File) error

	// ReadFile reads a file and returns its contents
	ReadFile(filePath string) ([]byte, error)

	// TempDir returns the temporary directory
	TempDir() string
}

FileSystem defines an interface for filesystem operations to enable mocking

func NewFileSystem

func NewFileSystem() FileSystem

type HTTPClient

type HTTPClient interface {
	// GetAndUnmarshal performs a GET request and unmarshals the response into result
	GetAndUnmarshal(ctx context.Context, url string, result interface{}) error

	// GetResponse performs a GET request and returns the full HTTP response
	// The caller is responsible for checking status code and closing the response body
	GetResponse(ctx context.Context, url string, headers map[string]string) (*http.Response, error)

	// GetResponseNoRetry performs a GET request and returns the full HTTP response without retry
	// The caller is responsible for checking status code and closing the response body
	GetResponseNoRetry(ctx context.Context, url string, headers map[string]string) (*http.Response, error)

	// GetBytes performs a GET request with custom headers and returns the response body
	GetBytes(ctx context.Context, url string, headers map[string]string) ([]byte, error)

	// GetPartialBytes performs a GET request with Range header to fetch partial content
	// Returns the partial content as bytes
	GetPartialBytes(ctx context.Context, url string, maxBytes int) ([]byte, error)

	// GetPartialBytesNoRetry performs a GET request with Range header to fetch partial content without retry
	// Returns the partial content as bytes
	GetPartialBytesNoRetry(ctx context.Context, url string, maxBytes int) ([]byte, error)

	// PostBytes performs a POST request and returns the response body as bytes
	PostBytes(ctx context.Context, url string, headers map[string]string, body io.Reader) ([]byte, error)

	// PostNoRetry performs a POST request with custom headers and returns the response without retry
	PostNoRetry(ctx context.Context, url string, headers map[string]string, body io.Reader) (*http.Response, error)

	// Head performs a HEAD request
	// The caller is responsible for closing the response body
	Head(ctx context.Context, url string) (*http.Response, error)

	// HeadNoRetry performs a HEAD request without retry
	HeadNoRetry(ctx context.Context, url string) (*http.Response, error)
}

HTTPClient defines an interface for HTTP client operations to enable mocking

func NewHTTPClient

func NewHTTPClient(timeout time.Duration) HTTPClient

NewHTTPClient creates a new real HTTP client

type IO added in v0.4.0

type IO interface {
	ReadAll(r io.Reader) ([]byte, error)
	Discard(r io.Reader) error
}

IO defines an interface for IO operations to enable mocking

func NewIO added in v0.4.0

func NewIO() IO

NewIO creates a new real IO implementation

type ImageEncoder added in v0.4.0

type ImageEncoder interface {
	// EncodePNG encodes an image to PNG format
	EncodePNG(w io.Writer, img image.Image) error
	// EncodeJPEG encodes an image to JPEG format with specified quality
	EncodeJPEG(w io.Writer, img image.Image, quality int) error
}

ImageEncoder defines an interface for encoding images

func NewImageEncoder added in v0.4.0

func NewImageEncoder() ImageEncoder

NewImageEncoder creates a new real image encoder

type JCS

type JCS interface {
	Transform(data []byte) ([]byte, error)
}

JCS defines an interface for JCS operations to enable mocking

func NewJCS

func NewJCS() JCS

NewJCS creates a new real JCS implementation

type JSON

type JSON interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
}

JSON defines an interface for JSON operations to enable mocking

func NewJSON

func NewJSON() JSON

NewJSON creates a new real JSON implementation

type RealBase64

type RealBase64 struct{}

func (*RealBase64) Decode

func (b *RealBase64) Decode(data string) ([]byte, error)

func (*RealBase64) Encode

func (b *RealBase64) Encode(data []byte) string

type RealChromedpClient added in v0.5.0

type RealChromedpClient struct{}

func (*RealChromedpClient) EmulateViewport added in v0.5.0

func (c *RealChromedpClient) EmulateViewport(width, height int64) chromedp.EmulateAction

func (*RealChromedpClient) Evaluate added in v0.5.0

func (c *RealChromedpClient) Evaluate(expr string, result interface{}, options ...chromedp.EvaluateOption) chromedp.EvaluateAction

func (*RealChromedpClient) FullScreenshot added in v0.5.0

func (c *RealChromedpClient) FullScreenshot(result *[]byte, quality int) chromedp.Action

func (*RealChromedpClient) Navigate added in v0.5.0

func (*RealChromedpClient) NewContext added in v0.5.0

func (*RealChromedpClient) NewExecAllocator added in v0.5.0

func (*RealChromedpClient) Run added in v0.5.0

func (c *RealChromedpClient) Run(ctx context.Context, actions ...chromedp.Action) error

func (*RealChromedpClient) Sleep added in v0.5.0

func (c *RealChromedpClient) Sleep(duration time.Duration) chromedp.Action

func (*RealChromedpClient) WaitReady added in v0.5.0

func (c *RealChromedpClient) WaitReady(sel string, waitReadyOpts ...chromedp.QueryOption) chromedp.QueryAction

type RealClock

type RealClock struct{}

RealClock implements Clock using the standard time package

func (*RealClock) After

func (c *RealClock) After(d time.Duration) <-chan time.Time

func (*RealClock) NewTicker

func (c *RealClock) NewTicker(d time.Duration) *time.Ticker

func (*RealClock) Now

func (c *RealClock) Now() time.Time

func (*RealClock) Parse

func (c *RealClock) Parse(layout, value string) (time.Time, error)

func (*RealClock) Since

func (c *RealClock) Since(t time.Time) time.Duration

func (*RealClock) Sleep

func (c *RealClock) Sleep(d time.Duration)

func (*RealClock) Unix

func (c *RealClock) Unix(sec int64, nsec int64) time.Time

type RealCloudflareClient

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

RealCloudflareClient implements CloudflareClient using the official Cloudflare SDK

func (*RealCloudflareClient) GetImage

GetImage gets the details of an uploaded image

func (*RealCloudflareClient) GetVideo

GetVideo retrieves video details from Cloudflare Stream

func (*RealCloudflareClient) UploadImage

UploadImage uploads a single image to Cloudflare Images

func (*RealCloudflareClient) UploadVideoFromFile

UploadVideoFromFile uploads a video to Cloudflare Stream from a file path

func (*RealCloudflareClient) UploadVideoFromURL

UploadVideoFromURL uploads a video to Cloudflare Stream via URL

type RealEthClient added in v0.5.0

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

RealEthClient wraps the ethclient.Client with retry logic

func NewRealEthClient added in v0.5.0

func NewRealEthClient(client *ethclient.Client, url string) *RealEthClient

NewRealEthClient creates a new RealEthClient

func (*RealEthClient) BlockByNumber added in v0.5.0

func (c *RealEthClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)

BlockByNumber returns a block by number with retry logic

func (*RealEthClient) CallContract added in v0.5.0

func (c *RealEthClient) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

CallContract calls a contract function with retry logic

func (*RealEthClient) Close added in v0.5.0

func (c *RealEthClient) Close()

Close closes the connection

func (*RealEthClient) CodeAt added in v0.5.0

func (c *RealEthClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)

CodeAt returns the code of the given account at the given block number with retry logic

func (*RealEthClient) FilterLogs added in v0.5.0

func (c *RealEthClient) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)

FilterLogs retrieves logs that match the filter query with retry logic

func (*RealEthClient) HeaderByNumber added in v0.5.0

func (c *RealEthClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber returns a header by number with retry logic

func (*RealEthClient) SubscribeFilterLogs added in v0.5.0

func (c *RealEthClient) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

SubscribeFilterLogs subscribes to filter logs with retry logic

func (*RealEthClient) TransactionReceipt added in v0.5.0

func (c *RealEthClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

TransactionReceipt returns the receipt of a transaction by transaction hash with retry logic

func (*RealEthClient) TransactionSender added in v0.5.0

func (c *RealEthClient) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)

TransactionSender returns the sender address of a transaction with retry logic

type RealEthClientDialer

type RealEthClientDialer struct{}

RealEthClientDialer implements EthClientDialer using the standard ethclient package

func (*RealEthClientDialer) Dial

func (a *RealEthClientDialer) Dial(ctx context.Context, rawurl string) (EthClient, error)

type RealFileSystem

type RealFileSystem struct{}

func (*RealFileSystem) Close added in v0.5.0

func (f *RealFileSystem) Close(file *os.File) error

func (*RealFileSystem) Create

func (f *RealFileSystem) Create(name string) (*os.File, error)

func (*RealFileSystem) CreateTemp added in v0.5.0

func (f *RealFileSystem) CreateTemp(dir, pattern string) (*os.File, error)

func (*RealFileSystem) ReadFile

func (f *RealFileSystem) ReadFile(filePath string) ([]byte, error)

func (*RealFileSystem) Remove

func (f *RealFileSystem) Remove(name string) error

func (*RealFileSystem) TempDir

func (f *RealFileSystem) TempDir() string

func (*RealFileSystem) WriteFile added in v0.5.0

func (f *RealFileSystem) WriteFile(file *os.File, data []byte) (int, error)

type RealHTTPClient

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

RealHTTPClient implements HTTPClient using the standard http package

func (*RealHTTPClient) GetAndUnmarshal added in v0.5.0

func (c *RealHTTPClient) GetAndUnmarshal(ctx context.Context, url string, result interface{}) error

GetAndUnmarshal performs a GET request and unmarshals the response into result Implements exponential backoff retry for rate limiting (429) responses

func (*RealHTTPClient) GetBytes added in v0.5.0

func (c *RealHTTPClient) GetBytes(ctx context.Context, url string, headers map[string]string) ([]byte, error)

GetBytes performs a GET request with custom headers and returns the response body Implements exponential backoff retry for rate limiting (429) responses

func (*RealHTTPClient) GetPartialBytes added in v0.5.0

func (c *RealHTTPClient) GetPartialBytes(ctx context.Context, url string, maxBytes int) ([]byte, error)

GetPartialBytes performs a GET request with Range header to fetch partial content Returns the partial content as bytes

func (*RealHTTPClient) GetPartialBytesNoRetry added in v0.5.0

func (c *RealHTTPClient) GetPartialBytesNoRetry(ctx context.Context, url string, maxBytes int) ([]byte, error)

GetPartialBytesNoRetry performs a GET request with Range header to fetch partial content without retry Returns the partial content as bytes

func (*RealHTTPClient) GetResponse added in v0.5.0

func (c *RealHTTPClient) GetResponse(ctx context.Context, url string, headers map[string]string) (*http.Response, error)

GetResponse performs a GET request and returns the full HTTP response The caller is responsible for checking status code and closing the response body

func (*RealHTTPClient) GetResponseNoRetry added in v0.5.0

func (c *RealHTTPClient) GetResponseNoRetry(ctx context.Context, url string, headers map[string]string) (*http.Response, error)

GetResponseNoRetry performs a GET request and returns the full HTTP response without retry The caller is responsible for checking status code and closing the response body

func (*RealHTTPClient) Head

func (c *RealHTTPClient) Head(ctx context.Context, url string) (*http.Response, error)

Head performs a HEAD request The caller is responsible for closing the response body

func (*RealHTTPClient) HeadNoRetry added in v0.5.0

func (c *RealHTTPClient) HeadNoRetry(ctx context.Context, url string) (*http.Response, error)

HeadNoRetry performs a HEAD request without retry

func (*RealHTTPClient) PostBytes added in v0.5.0

func (c *RealHTTPClient) PostBytes(ctx context.Context, url string, headers map[string]string, body io.Reader) ([]byte, error)

PostBytes performs a POST request and returns the response body Implements exponential backoff retry for rate limiting (429) responses

func (*RealHTTPClient) PostNoRetry added in v0.5.0

func (c *RealHTTPClient) PostNoRetry(ctx context.Context, url string, headers map[string]string, body io.Reader) (*http.Response, error)

PostNoRetry performs a POST request with custom headers and returns the response without retry

type RealIO added in v0.4.0

type RealIO struct{}

RealIO implements IO using the standard io package

func (*RealIO) Discard added in v0.5.0

func (i *RealIO) Discard(r io.Reader) error

func (*RealIO) ReadAll added in v0.4.0

func (i *RealIO) ReadAll(r io.Reader) ([]byte, error)

type RealImageEncoder added in v0.4.0

type RealImageEncoder struct{}

RealImageEncoder implements ImageEncoder using standard library

func (*RealImageEncoder) EncodeJPEG added in v0.4.0

func (e *RealImageEncoder) EncodeJPEG(w io.Writer, img image.Image, quality int) error

EncodeJPEG encodes an image to JPEG format with specified quality

func (*RealImageEncoder) EncodePNG added in v0.4.0

func (e *RealImageEncoder) EncodePNG(w io.Writer, img image.Image) error

EncodePNG encodes an image to PNG format

type RealJCS

type RealJCS struct{}

RealJCS implements JCS using the standard jcs package

func (*RealJCS) Transform

func (j *RealJCS) Transform(data []byte) ([]byte, error)

type RealJSON

type RealJSON struct{}

RealJSON implements JSON using the standard encoding/json package

func (*RealJSON) Marshal

func (j *RealJSON) Marshal(v interface{}) ([]byte, error)

func (*RealJSON) Unmarshal

func (j *RealJSON) Unmarshal(data []byte, v interface{}) error

type RealResvgClient added in v0.4.0

type RealResvgClient struct{}

RealResvgClient implements ResvgClient using the actual resvg library

func (*RealResvgClient) Render added in v0.4.0

func (c *RealResvgClient) Render(data []byte, width int) (image.Image, error)

Render renders SVG data to an image using resvg with best fit scaling

type RealSignalR

type RealSignalR struct{}

RealSignalR implements SignalR using the standard signalr package

func (*RealSignalR) NewClient

func (s *RealSignalR) NewClient(ctx context.Context, address string, receiver interface{}) (SignalRClient, error)

type RealVipsClient added in v0.5.0

type RealVipsClient struct{}

RealVipsClient implements VipsClient using the actual vipsgen/vips library

func (*RealVipsClient) NewImageFromSource added in v0.5.0

func (v *RealVipsClient) NewImageFromSource(source VipsSource, options *vips.LoadOptions) (VipsImage, error)

func (*RealVipsClient) NewSource added in v0.5.0

func (v *RealVipsClient) NewSource(reader io.ReadCloser) VipsSource

func (*RealVipsClient) Shutdown added in v0.5.0

func (v *RealVipsClient) Shutdown()

func (*RealVipsClient) Startup added in v0.5.0

func (v *RealVipsClient) Startup(config *vips.Config)

type RealXML added in v0.5.0

type RealXML struct{}

func (*RealXML) Unmarshal added in v0.5.0

func (x *RealXML) Unmarshal(data []byte, v interface{}) error

type ResvgClient added in v0.4.0

type ResvgClient interface {
	// Render renders SVG data to an image with specified width (0 = use SVG natural size)
	// Uses ScaleBestFit mode to maintain aspect ratio
	Render(data []byte, width int) (image.Image, error)
}

ResvgClient defines an interface for SVG rendering using resvg

func NewResvgClient added in v0.4.0

func NewResvgClient() ResvgClient

NewResvgClient creates a new real resvg client

type SignalR

type SignalR interface {
	NewClient(ctx context.Context, address string, receiver interface{}) (SignalRClient, error)
}

SignalR defines an interface for creating SignalR clients

func NewSignalR

func NewSignalR() SignalR

NewSignalR creates a new real SignalR

type SignalRClient

type SignalRClient interface {
	Start()
	Send(target string, args ...interface{}) <-chan error
	Stop()
}

SignalRClient defines an interface for SignalR client operations to enable mocking

type VipsClient added in v0.5.0

type VipsClient interface {
	// Startup initializes libvips
	Startup(config *vips.Config)

	// Shutdown shuts down libvips
	Shutdown()

	// NewSource creates a new vips source from an io.ReadCloser
	NewSource(reader io.ReadCloser) VipsSource

	// NewImageFromSource loads an image from a source
	NewImageFromSource(source VipsSource, options *vips.LoadOptions) (VipsImage, error)
}

VipsClient defines an interface for libvips operations to enable mocking

func NewVipsClient added in v0.5.0

func NewVipsClient() VipsClient

NewVipsClient creates a new real vips client implementation

type VipsImage added in v0.5.0

type VipsImage interface {
	Width() int
	Height() int
	HasAlpha() bool
	Pages() int
	PageHeight() int
	SetPageHeight(height int) error
	Resize(scale float64, options *vips.ResizeOptions) error
	ExtractArea(left, top, width, height int) error
	JpegsaveBuffer(options *vips.JpegsaveBufferOptions) ([]byte, error)
	WebpsaveBuffer(options *vips.WebpsaveBufferOptions) ([]byte, error)
	GetInt(name string) (int, error)
	SetInt(name string, i int)
	GetArrayInt(name string) ([]int, error)
	SetArrayInt(name string, values []int) error
	GetFields() []string
	Close()
}

VipsImage wraps vips.Image to provide a mockable interface

type VipsSource added in v0.5.0

type VipsSource interface {
	Close()
}

VipsSource wraps vips.Source to provide a mockable interface

type XML added in v0.5.0

type XML interface {
	Unmarshal(data []byte, v interface{}) error
}

XML defines an interface for XML operations to enable mocking

func NewXML added in v0.5.0

func NewXML() XML

Jump to

Keyboard shortcuts

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