Documentation
¶
Index ¶
- Constants
- func BuildRawURL(cdnBase, project, imageKey string) string
- func BuildSrcSet(cdnBase, project, imageKey string, opts SrcSetOptions) string
- func BuildURL(cdnBase, project, imageKey string, opts Options) string
- func GuessContentType(filename, headerType string) string
- func IsURL(src string) bool
- func RewriteURL(src string, opts Options) string
- func SanitizeFilename(name string) string
- func SizesAttr(maxWidth int) string
- func SrcSetFromURL(src string, opts SrcSetOptions) string
- type Client
- func (c *Client) Configured() bool
- func (c *Client) Delete(ctx context.Context, imageKey string) error
- func (c *Client) ListImages(ctx context.Context, params ListImagesParams) (*ListImagesResponse, error)
- func (c *Client) ListProjects(ctx context.Context) ([]Project, error)
- func (c *Client) Moderate(ctx context.Context, imageKey string) (*ModerationResult, error)
- func (c *Client) Presign(ctx context.Context, filename, contentType string, sizes []Size) (*PresignResult, error)
- func (c *Client) PresignMany(ctx context.Context, files []FileSpec, sizes []Size) ([]PresignResult, error)
- func (c *Client) PublicURL(imageKey string) string
- func (c *Client) Put(ctx context.Context, uploadURL, contentType string, body io.Reader) error
- func (c *Client) RawURL(imageKey string) string
- func (c *Client) SrcSet(imageKey string, opts SrcSetOptions) string
- func (c *Client) URL(imageKey string, opts Options) string
- func (c *Client) Upload(ctx context.Context, file Upload) (*UploadResult, error)
- func (c *Client) UploadMany(ctx context.Context, files []Upload) ([]UploadResult, error)
- type Config
- type Error
- type FileSpec
- type Image
- type ListImagesParams
- type ListImagesResponse
- type ModerationLabel
- type ModerationResult
- type Options
- type PresignResult
- type Project
- type Size
- type SrcSetOptions
- type Upload
- type UploadResult
Constants ¶
const ( // DefaultAPIBase is the production FireImg API. DefaultAPIBase = "https://api.fireimg.com" // DefaultCDNBase is the production FireImg CDN. DefaultCDNBase = "https://img.fireimg.com" // MaxFilesPerRequest is the API limit for one presign call. MaxFilesPerRequest = 20 // MaxSizesPerRequest is the API limit for pre-generated variants. MaxSizesPerRequest = 20 // MaxConcurrentPuts is how many S3 PUTs UploadMany runs at once. MaxConcurrentPuts = 4 )
const Version = "0.1.1"
Version is the library version used in the User-Agent header.
Variables ¶
This section is empty.
Functions ¶
func BuildRawURL ¶
BuildRawURL constructs a raw-bytes CDN URL.
func BuildSrcSet ¶
func BuildSrcSet(cdnBase, project, imageKey string, opts SrcSetOptions) string
BuildSrcSet constructs a srcset string for an image key.
func GuessContentType ¶
GuessContentType returns headerType when it is a usable MIME type, otherwise an image type inferred from the filename extension.
func RewriteURL ¶
RewriteURL applies opts to an existing URL. Existing query params are kept unless overwritten. Width and height are updated only when greater than zero.
func SanitizeFilename ¶
SanitizeFilename cleans an image key. Folders are preserved; each segment keeps letters, digits, dot, dash, and underscore. ".." is rejected.
func SrcSetFromURL ¶
func SrcSetFromURL(src string, opts SrcSetOptions) string
SrcSetFromURL builds a srcset by rewriting widths on an existing FireImg URL.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the FireImg API and builds CDN URLs.
func New ¶
New returns a client. Empty config fields fall back to FIREIMG_* environment variables. URL helpers work without an API key; upload and management calls require both APIKey and Project.
func (*Client) Configured ¶
Configured reports whether API-key operations can run.
func (*Client) ListImages ¶
func (c *Client) ListImages(ctx context.Context, params ListImagesParams) (*ListImagesResponse, error)
ListImages returns one page of images for the configured project.
func (*Client) ListProjects ¶
ListProjects returns every project the API key's team can access.
func (*Client) Moderate ¶
Moderate runs a Rekognition content scan. JPEG and PNG only. The result is labels for the app to apply policy; FireImg does not reject the image.
func (*Client) Presign ¶
func (c *Client) Presign(ctx context.Context, filename, contentType string, sizes []Size) (*PresignResult, error)
Presign requests one presigned S3 PUT URL.
func (*Client) PresignMany ¶
func (c *Client) PresignMany(ctx context.Context, files []FileSpec, sizes []Size) ([]PresignResult, error)
PresignMany requests presigned S3 PUT URLs for up to MaxFilesPerRequest files. A nil sizes slice omits the field; a non-nil empty slice sends [].
func (*Client) SrcSet ¶
func (c *Client) SrcSet(imageKey string, opts SrcSetOptions) string
SrcSet builds a comma-separated srcset from Widths or a min/max/step range.
func (*Client) URL ¶
URL is the CDN URL with the given transform options. Only set fields are emitted. The query key for format is "format"; Options.Fmt is accepted as an alias.
func (*Client) UploadMany ¶
UploadMany presigns and PUTs up to MaxFilesPerRequest files. Shared Sizes come from the first file that sets them (including an explicit empty slice).
type Config ¶
type Config struct {
APIKey string
Project string
APIBase string
CDNBase string
HTTPClient *http.Client
}
Config holds client settings. Empty APIKey, Project, APIBase, and CDNBase fall back to FIREIMG_API_KEY, FIREIMG_PROJECT, FIREIMG_API_BASE, and FIREIMG_CDN_BASE. Staging uses https://api.fireimg.dev and https://img.fireimg.dev.
type Image ¶
type Image struct {
ImageKey string `json:"imageKey"`
S3RawKey string `json:"s3RawKey"`
UploadedAt string `json:"uploadedAt"`
OriginalSizeBytes int64 `json:"originalSizeBytes"`
ContentType string `json:"contentType"`
VariationsGeneratedCount int `json:"variationsGeneratedCount,omitempty"`
CacheVersion int `json:"cacheVersion,omitempty"`
}
Image is one entry from GET /v1/api/projects/{slug}/images.
type ListImagesParams ¶
ListImagesParams are query options for GET /v1/api/projects/{slug}/images.
type ListImagesResponse ¶
type ListImagesResponse struct {
Images []Image `json:"images"`
Folder string `json:"folder"`
NextToken string `json:"nextToken,omitempty"`
}
ListImagesResponse is one page of images.
type ModerationLabel ¶
type ModerationLabel struct {
Name string `json:"name"`
Parent string `json:"parent"`
Confidence float64 `json:"confidence"`
}
ModerationLabel is one Rekognition label from a content scan.
type ModerationResult ¶
type ModerationResult struct {
Moderation string `json:"moderation"`
Labels []ModerationLabel `json:"labels,omitempty"`
Reason string `json:"reason,omitempty"`
}
ModerationResult is the body of POST .../images/moderation/{imageKey}.
type Options ¶
type Options struct {
Width int
Height int
Quality string
Format string
Fmt string
Fit string
Pos string
Position string
Fill string
Version int
}
Options are CDN transform query parameters. Only set fields are emitted; quality and format are not defaulted.
type PresignResult ¶
PresignResult is one entry from POST /v1/api/presigned-upload-urls.
type Project ¶
type Project struct {
ProjectName string `json:"projectName"`
Slug string `json:"slug"`
TeamID string `json:"teamId,omitempty"`
CreatedAt string `json:"createdAt"`
}
Project is one entry from GET /v1/api/projects.
type Size ¶
type Size struct {
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Quality string `json:"quality,omitempty"`
Fmt string `json:"fmt,omitempty"`
Fit string `json:"fit,omitempty"`
Pos string `json:"pos,omitempty"`
Fill string `json:"fill,omitempty"`
}
Size is one variant to pre-generate after upload. These replace the project's default image params for that upload. An empty slice still overrides defaults and pre-generates only FireImg's 80px dashboard thumbnail.
func SizesForWidths ¶
SizesForWidths builds width-only pre-generation sizes.
type SrcSetOptions ¶
SrcSetOptions build a responsive srcset. Use Widths for an explicit ladder, or MinWidth/MaxWidth/SnapStep (defaults 100/2000/100) like @fireimg/js.
type Upload ¶
type Upload struct {
Filename string
ContentType string
Body io.Reader
Bytes []byte
Path string
Sizes []Size
}
Upload is one file to presign and PUT.
Provide bytes with Body, Bytes, or Path. Sizes is optional: nil keeps the project defaults; a non-nil empty slice sends [] and pre-generates only the dashboard thumbnail.