Documentation
¶
Overview ¶
Package image handles storing, resizing and retrieval of images Provides Store with Save and Load and one implementation on top of local file system. Service object encloses Store and add common methods, this is the one consumer should use
Index ¶
- type Bolt
- func (b *Bolt) Cleanup(ctx context.Context, ttl time.Duration) error
- func (b *Bolt) Commit(id string) error
- func (b *Bolt) Load(id string) (io.ReadCloser, int64, error)
- func (b *Bolt) Save(fileName string, userID string, r io.Reader) (id string, err error)
- func (b *Bolt) SaveWithID(id string, r io.Reader) (string, error)
- func (b *Bolt) SizeLimit() int
- type FileSystem
- func (f *FileSystem) Cleanup(ctx context.Context, ttl time.Duration) error
- func (f *FileSystem) Commit(id string) error
- func (f *FileSystem) Load(id string) (io.ReadCloser, int64, error)
- func (f *FileSystem) Save(fileName string, userID string, r io.Reader) (id string, err error)
- func (f *FileSystem) SaveWithID(id string, r io.Reader) (string, error)
- func (f *FileSystem) SizeLimit() int
- type MockStore
- func (_m *MockStore) Cleanup(ctx context.Context, ttl time.Duration) error
- func (_m *MockStore) Commit(id string) error
- func (_m *MockStore) Load(id string) (io.ReadCloser, int64, error)
- func (_m *MockStore) Save(fileName string, userID string, r io.Reader) (string, error)
- func (_m *MockStore) SaveWithID(id string, r io.Reader) (string, error)
- func (_m *MockStore) SizeLimit() int
- type Service
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bolt ¶ added in v1.5.0
type Bolt struct { MaxSize int MaxHeight int MaxWidth int // contains filtered or unexported fields }
Bolt provides image Store for images keeping data in bolt DB, restricts max size. It uses 3 buckets to manage images data. Two buckets contains image data (staged and committed images). Third bucket holds insertion timestamps.
func NewBoltStorage ¶ added in v1.5.0
func NewBoltStorage(fileName string, maxSize int, maxHeight int, maxWidth int, options bolt.Options) (*Bolt, error)
Create Bolt Store.
func (*Bolt) Cleanup ¶ added in v1.5.0
Cleanup runs scan of staging and removes old data based on ttl
func (*Bolt) Commit ¶ added in v1.5.0
Commit file stored in staging bucket by copying it to permanent bucket Data from staging bucket not removed immediately, but would be removed on cleanup
func (*Bolt) Load ¶ added in v1.5.0
Load image from DB returns ReadCloser and caller should call close after processing completed.
func (*Bolt) SaveWithID ¶ added in v1.5.0
SaveWithID saves data from reader with given id
type FileSystem ¶
type FileSystem struct { Location string Staging string MaxSize int Partitions int MaxHeight int MaxWidth int // contains filtered or unexported fields }
FileSystem provides image Store for local files. Saves and loads files from Location, restricts max size.
func (*FileSystem) Commit ¶
func (f *FileSystem) Commit(id string) error
Commit file stored in staging location by moving it to permanent location
func (*FileSystem) Load ¶
func (f *FileSystem) Load(id string) (io.ReadCloser, int64, error)
Load image from FS. Uses id to get partition subdirectory. returns ReadCloser and caller should call close after processing completed.
func (*FileSystem) Save ¶
Save data from reader for given file name to local FS, staging directory. Returns id as user/uuid Files partitioned across multiple subdirectories and the final path includes part, i.e. /location/user1/03/123-4567
func (*FileSystem) SaveWithID ¶ added in v1.5.0
SaveWithID saves data from reader with given id
func (*FileSystem) SizeLimit ¶
func (f *FileSystem) SizeLimit() int
SizeLimit returns max size of allowed image
type MockStore ¶
MockStore is an autogenerated mock type for the Store type
func (*MockStore) SaveWithID ¶ added in v1.5.0
SaveWithID provides a mock function with given fields: id, r
type Service ¶
type Service struct { Store TTL time.Duration // for how long file allowed on staging ImageAPI string // image api matching path // contains filtered or unexported fields }
Service extends Store with common functions needed for any store implementation
func (*Service) Cleanup ¶
Cleanup runs periodic cleanup with TTL. Blocking loop, should be called inside of goroutine by consumer
func (*Service) Close ¶
func (s *Service) Close()
Close flushes all in-progress submits and enforces waiting commits
func (*Service) ExtractPictures ¶
ExtractPictures gets list of images from the doc html and convert from urls to ids, i.e. user/pic.png
type Store ¶
type Store interface { SaveWithID(id string, r io.Reader) (string, error) Save(fileName string, userID string, r io.Reader) (id string, err error) // get name and reader and returns ID of stored image Commit(id string) error // move image from staging to permanent Load(id string) (io.ReadCloser, int64, error) // load image by ID. Caller has to close the reader. Cleanup(ctx context.Context, ttl time.Duration) error // run removal loop for old images on staging SizeLimit() int // max image size }
Store defines interface for saving and loading pictures. Declares two-stage save with commit