Documentation
¶
Overview ¶
Package yourimageshare is the official Go client for the YourImageShare upload API (https://yourimageshare.com/about/api). It mirrors the existing JS (npm), Python (PyPI), and PHP (Packagist) SDKs - same method names, same result shapes, same error type - just idiomatic Go on top (methods return (result, error), not exceptions).
Zero third-party dependencies - only the standard library.
Index ¶
Constants ¶
const DefaultBaseURL = "https://yourimageshare.com/api"
DefaultBaseURL is used when no WithBaseURL option is given.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError is returned for any non-2xx response or a `{"type":"error"}` payload - mirrors the JS/Python/PHP SDKs' error type exactly (same Status/Message shape) so error-handling logic reads the same across every official SDK.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the YourImageShare upload API. Create one with NewClient; a Client is safe for concurrent use by multiple goroutines (it holds no mutable state after construction).
func NewClient ¶
NewClient creates a Client. apiKey is required - get one from the API tab at https://yourimageshare.com/my-account.
func (*Client) Delete ¶
Delete removes one of your uploads by id. Returns an *APIError on a 404/401.
func (*Client) List ¶
func (c *Client) List(page int) (*ListResult, error)
List returns your uploads, newest first, 50 per page. page < 2 fetches the first page.
func (*Client) Upload ¶
func (c *Client) Upload(filePath string, opts *UploadOptions) (*UploadResult, error)
Upload uploads a local file by path.
func (*Client) UploadReader ¶
func (c *Client) UploadReader(r io.Reader, filename string, opts *UploadOptions) (*UploadResult, error)
UploadReader uploads from any io.Reader (an open file, a network stream, an in-memory buffer) - useful when the data isn't already a file on disk. filename should include a real extension so the server can infer the content type correctly.
type ListMeta ¶
type ListMeta struct {
CurrentPage int `json:"current_page"`
LastPage int `json:"last_page"`
Total int `json:"total"`
}
ListMeta carries the pagination info for a List() result.
type ListResult ¶
type ListResult struct {
Data []ListedUpload `json:"data"`
Meta ListMeta `json:"meta"`
}
ListResult is the response shape for List().
type ListedUpload ¶
type ListedUpload struct {
ID string `json:"id"`
Type string `json:"type"`
Title *string `json:"title"`
Path string `json:"path"`
Src string `json:"src"`
Direct string `json:"direct"`
ExpiresAt *string `json:"expires_at"`
CreatedAt string `json:"created_at"`
}
ListedUpload is one row of a List() result.
type Option ¶
type Option func(*Client)
Option configures a Client. See WithBaseURL and WithHTTPClient.
func WithBaseURL ¶
WithBaseURL overrides the API base URL - mainly for testing against a different environment. Defaults to DefaultBaseURL.
func WithHTTPClient ¶
WithHTTPClient overrides the *http.Client used for requests, e.g. to set a custom timeout or transport. Defaults to a client with a 30s timeout.
type UploadOptions ¶
type UploadOptions struct {
// ExpiresIn auto-deletes the upload after this many seconds (60 to
// 2,592,000 = 30 days). Zero means a permanent upload.
ExpiresIn int
}
UploadOptions are the optional parameters for Upload/UploadReader.
type UploadResult ¶
type UploadResult struct {
ID string `json:"id"`
Type string `json:"type"`
Path string `json:"path"`
Src string `json:"src"`
Direct string `json:"direct"`
ExpiresAt *string `json:"expires_at"`
}
UploadResult is the response shape for a successful upload - same fields as the JS/Python/PHP SDKs' UploadResult.