media

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package media defines the files the media library holds.

Index

Constants

This section is empty.

Variables

View Source
var ErrConflict = errors.New("media: conflicting update")

ErrConflict reports that the media item changed after the update was prepared.

View Source
var ErrInvalidAuthor = errors.New("media: invalid author")

ErrInvalidAuthor reports that a media item carries no author.

View Source
var ErrInvalidFile = errors.New("media: invalid file")

ErrInvalidFile reports that a media item names no stored file.

View Source
var ErrInvalidMime = errors.New("media: invalid mime type")

ErrInvalidMime reports that a media item carries no content type.

View Source
var ErrInvalidType = errors.New("media: invalid type")

ErrInvalidType reports that a media kind is not one the library tells apart.

View Source
var ErrNotFound = errors.New("media: not found")

ErrNotFound reports that no media item exists for the requested ID.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Type    Type
	Mimes   []string
	Search  string
	Page    int
	PerPage int
}

Filter narrows a media listing to the type, content type prefixes and search it carries.

type Media

type Media struct {
	ID          int64
	Type        Type
	File        string
	Title       string
	AltText     string
	Caption     string
	Description string
	MimeType    string
	Width       int
	Height      int
	Filesize    int64
	Sizes       RenditionMap
	AuthorID    uuid.UUID
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Media is a stored upload with the descriptions the editor reads.

func New

func New(file, title, mimeType string, authorID uuid.UUID) (Media, error)

New returns a Media item over a stored file, typed after its content type.

type Rendition

type Rendition struct {
	File     string `json:"file"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
	MimeType string `json:"mime_type"`
	Filesize int64  `json:"filesize"`
}

Rendition is one derived copy of an image bounded to a size.

type RenditionMap

type RenditionMap map[string]Rendition

RenditionMap holds a media item's renditions keyed by size slug.

type Store

type Store interface {
	Create(ctx context.Context, m Media) (Media, error)
	ByID(ctx context.Context, id int64) (Media, error)
	List(ctx context.Context, f Filter) ([]Media, int, error)
	Update(ctx context.Context, m Media, expectedUpdatedAt time.Time) (Media, error)
	Delete(ctx context.Context, id int64) (Media, error)
}

Store persists the media library.

type Type

type Type string

Type sorts a media item into the kinds the library tells apart.

const (
	TypeImage Type = "image"
	TypeFile  Type = "file"
)

The kinds of media the library tells apart.

func ParseType

func ParseType(raw string) (Type, error)

ParseType returns the kind named by raw, or ErrInvalidType.

Jump to

Keyboard shortcuts

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