Documentation
¶
Overview ¶
Package tinypng provides a client implementation for the `tinypng.com` API.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( errors.New("unauthorized (invalid credentials)") // ErrTooManyRequests indicates that the API request limit has been exceeded. ErrTooManyRequests = errors.New("too many requests (limit exceeded)") // ErrBadRequest indicates an issue with the request, such as an empty file or an unsupported format. ErrBadRequest = errors.New("bad request (empty file or unsupported format)") )ErrUnauthorized =
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents the TinyPNG API client.
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) *Client
NewClient creates a new TinyPNG client instance with the specified API key. Additional options can be provided to customize the client.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a functional option used to configure the Client instance.
func WithHTTPClient ¶
func WithHTTPClient(httpClient httpClient) ClientOption
WithHTTPClient allows the use of a custom HTTP client implementation.
type ClientsPool ¶
type ClientsPool struct {
// contains filtered or unexported fields
}
func NewClientsPool ¶
func NewClientsPool(apiKeys []string, opts ...ClientOption) *ClientsPool
NewClientsPool initializes a new pool of clients using the given API keys. Additional options can be provided to customize the clients.
func (*ClientsPool) Get ¶
func (p *ClientsPool) Get() (*Client, func(), bool)
Get retrieves a random client from the pool.
If the pool is empty, it returns nil and false as the last return value. If the client for a key is uninitialized, it creates a new one and returns it. The returned cleanup function should be called when the client is no longer needed, allowing the key to be removed from the pool.
type Compressed ¶
type Compressed struct { UsedQuota uint64 // Number of compressions used in the current billing period. Type string // MIME type of the compressed image, e.g., "image/png". Size uint64 // Size of the compressed image in bytes. URL string // URL of the compressed image. Width, Height uint32 // Dimensions of the compressed image. // contains filtered or unexported fields }
Compressed represents the result of a TinyPNG compression operation.
func (Compressed) Download ¶
func (c Compressed) Download(ctx context.Context, to io.Writer, opt ...DownloadOption) (outErr error)
Download retrieves the compressed image from the TinyPNG servers and writes it to the specified destination. If the provided destination implements io.Closer, it will be closed automatically by the HTTP client.
type DownloadOption ¶
type DownloadOption func(*downloadOptions)
func WithDownloadPreserveCopyright ¶
func WithDownloadPreserveCopyright() DownloadOption
WithDownloadPreserveCopyright specifies that the copyright information should be preserved.
func WithDownloadPreserveCreation ¶
func WithDownloadPreserveCreation() DownloadOption
WithDownloadPreserveCreation specifies that the creation date should be preserved.
func WithDownloadPreserveLocation ¶
func WithDownloadPreserveLocation() DownloadOption
WithDownloadPreserveLocation specifies that the GPS location should be preserved.