// Package format describes the file types the gallery can show. package format import ( "io" "path/filepath" "strings" "time" ) type Kind int const ( KindImage Kind = iota ) // Meta holds display metadata. Width and Height are after EXIF orientation. type Meta struct { Width, Height int Taken time.Time Camera, Lens string Aperture string Shutter string ISO int } type Format interface { Name() string Match(path string) bool Metadata(path string) (Meta, error) Resize(src string, width int, dst io.Writer) error Kind() Kind } // Registry resolves a path to the first registered Format that matches it. type Registry struct { formats []Format } func (r *Registry) Register(f Format) { r.formats = append(r.formats, f) } func (r *Registry) Lookup(path string) Format { for _, f := range r.formats { if f.Match(path) { return f } } return nil } func hasExt(path string, exts []string) bool { ext := strings.ToLower(filepath.Ext(path)) for _, e := range exts { if ext == e { return true } } return false }