media

package
v0.60.8 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrProviderUnavailable reports that no upstream media provider has been configured.
	ErrProviderUnavailable = errors.New("media: provider unavailable")
	// ErrAssetNotFound indicates that the requested media asset could not be located.
	ErrAssetNotFound = errors.New("media: asset not found")
	// ErrRenditionMissing reports that a required rendition was not supplied by the provider.
	ErrRenditionMissing = errors.New("media: required rendition missing")
)

Functions

func CloneAttachments

func CloneAttachments(src map[string][]*Attachment) map[string][]*Attachment

CloneAttachments performs a deep copy of a resolved media attachment map.

func NormalizeMany

func NormalizeMany(assets map[string]*interfaces.MediaAsset) map[string]*Attachment

NormalizeMany converts multiple resolved assets into attachments keyed by identifier.

Types

type Attachment

type Attachment struct {
	Reference  interfaces.MediaReference `json:"reference"`
	Metadata   interfaces.MediaMetadata  `json:"metadata"`
	Source     *Resource                 `json:"source,omitempty"`
	Renditions map[string]*Resource      `json:"renditions,omitempty"`
}

Attachment normalizes a resolved media asset for downstream consumption.

func CloneAttachment

func CloneAttachment(att *Attachment) *Attachment

CloneAttachment copies an attachment and its nested resources.

func Normalize

func Normalize(asset *interfaces.MediaAsset) *Attachment

Normalize converts a resolved media asset into an Attachment DTO.

type Binding

type Binding struct {
	Slot           string                    `json:"slot"`
	Reference      interfaces.MediaReference `json:"reference"`
	Renditions     []string                  `json:"renditions,omitempty"`
	Required       []string                  `json:"required,omitempty"`
	Locale         string                    `json:"locale,omitempty"`
	FallbackLocale string                    `json:"fallback_locale,omitempty"`
	Gallery        bool                      `json:"gallery,omitempty"`
	Position       int                       `json:"position,omitempty"`
	Metadata       map[string]any            `json:"metadata,omitempty"`
}

Binding associates a CMS entity slot with an upstream media reference.

type BindingSet

type BindingSet map[string][]Binding

BindingSet groups bindings under semantic keys (e.g. hero_image, gallery).

func CloneBindingSet

func CloneBindingSet(src BindingSet) BindingSet

CloneBindingSet performs a deep copy of the binding set to avoid shared references.

type ResolveOptions

type ResolveOptions struct {
	IncludeSignedURLs bool
	SignedURLTTL      time.Duration
	CacheTTL          time.Duration
}

ResolveOptions configures how media bindings should be resolved.

type Resource

type Resource struct {
	URL          string                `json:"url"`
	MimeType     string                `json:"mime_type,omitempty"`
	Size         int64                 `json:"size,omitempty"`
	Width        int                   `json:"width,omitempty"`
	Height       int                   `json:"height,omitempty"`
	Duration     time.Duration         `json:"duration,omitempty"`
	Hash         string                `json:"hash,omitempty"`
	SignedURL    *interfaces.SignedURL `json:"signed_url,omitempty"`
	LastModified time.Time             `json:"last_modified"`
	Metadata     map[string]any        `json:"metadata,omitempty"`
}

Resource captures a concrete representation of a media asset (original or derivative).

type Service

type Service interface {
	ResolveBindings(ctx context.Context, bindings BindingSet, opts ResolveOptions) (map[string][]*Attachment, error)
	Invalidate(ctx context.Context, bindings BindingSet) error
}

Service resolves media bindings into normalized attachments.

func NewNoOpService

func NewNoOpService() Service

NewNoOpService returns a media service that acts as a passthrough for disabled configurations.

func NewService

func NewService(provider interfaces.MediaProvider, opts ...ServiceOption) Service

NewService constructs a media helper service that delegates to the configured provider.

type ServiceOption

type ServiceOption func(*service)

ServiceOption customises the media service behaviour.

func WithCache

func WithCache(cache interfaces.CacheProvider, ttl time.Duration) ServiceOption

WithCache configures a cache provider and default TTL for resolved attachments.

func WithDefaultCacheTTL

func WithDefaultCacheTTL(ttl time.Duration) ServiceOption

WithDefaultCacheTTL sets the fallback TTL applied when ResolveOptions do not specify one.

func WithDefaultSignedURLTTL

func WithDefaultSignedURLTTL(ttl time.Duration) ServiceOption

WithDefaultSignedURLTTL sets the fallback TTL used when signed URLs are requested without an explicit expiry.

Jump to

Keyboard shortcuts

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