Documentation
¶
Overview ¶
Package image handles storing, resizing and retrieval of images Provides Store with Save and Load implementations on top of local file system and bolt db. Service object encloses Store and add common methods, this is the one consumer should use.
Index ¶
- func CachedImgID(imgURL string) (string, error)
- func Sha1Str(s string) string
- type Bolt
- type FileSystem
- type MockStore
- type RPC
- type Service
- func (s *Service) Cleanup(ctx context.Context)
- func (s *Service) Close(ctx context.Context)
- func (s *Service) ExtractPictures(commentHTML string) (ids []string, err error)
- func (s *Service) ImgContentType(img []byte) string
- func (s *Service) Info() (StoreInfo, error)
- func (s *Service) Load(id string) ([]byte, error)
- func (s *Service) Save(userID string, r io.Reader) (id string, err error)
- func (s *Service) SaveWithID(id string, r io.Reader) error
- func (s *Service) Submit(idsFn func() []string)
- func (s *Service) SubmitAndCommit(idsFn func() []string) error
- type ServiceParams
- type Store
- type StoreInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CachedImgID ¶
CachedImgID generates ID for a cached image. ID would look like: "cached_images/<sha1-of-image-url-hostname>-<sha1-of-image-entire-url>" <sha1-of-image-url-hostname> - would allow us to identify all images from particular site if ever needed <sha1-of-image-entire-url> - would allow us to avoid storing duplicates of the same image
(as accurate as deduplication based on potentially mutable url can be)
Types ¶
type Bolt ¶
type Bolt struct {
// 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 ¶
NewBoltStorage create bolt image store
func (*Bolt) Commit ¶
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
type FileSystem ¶
type FileSystem struct { Location string Staging string Partitions 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) Info ¶
func (f *FileSystem) Info() (StoreInfo, error)
Info returns meta information about storage
type MockStore ¶
MockStore is an autogenerated mock type for the Store type
type RPC ¶
RPC implements remote engine and delegates all Calls to remote http server
type Service ¶
type Service struct { ServiceParams // contains filtered or unexported fields }
Service wraps Store with common functions needed for any store implementation It also provides async Submit with func param retrieving all submitting ids. Submitted ids committed (i.e. moved from staging to final) on commitTTL expiration.
func NewService ¶
func NewService(s Store, p ServiceParams) *Service
NewService returns new Service instance
func (*Service) Cleanup ¶
Cleanup runs periodic cleanup with cleanupTTL. Blocking loop, should be called inside of goroutine by consumer
func (*Service) ExtractPictures ¶
ExtractPictures gets list of images from the doc html and convert from urls to ids, i.e. user/pic.png
func (*Service) ImgContentType ¶
ImgContentType returns content type for provided image
func (*Service) Save ¶
Save wraps storage Save function, validating and resizing the image before calling it.
func (*Service) SaveWithID ¶
SaveWithID wraps storage Save function, validating and resizing the image before calling it.
func (*Service) SubmitAndCommit ¶
SubmitAndCommit multiple ids immediately
type ServiceParams ¶
type ServiceParams struct { EditDuration time.Duration // edit period for comments ImageAPI string // image api matching path ProxyAPI string // proxy api matching path MaxSize int MaxHeight int MaxWidth int // contains filtered or unexported fields }
ServiceParams contains externally adjustable parameters of Service
type Store ¶
type Store interface { Info() (StoreInfo, error) // get meta information about storage Save(id string, img []byte) error // store image with passed id to staging Load(id string) ([]byte, error) // load image by ID Commit(id string) error // move image from staging to permanent Cleanup(ctx context.Context, ttl time.Duration) error // run removal loop for old images on staging }
Store defines interface for saving and loading pictures. Declares two-stage save with Commit. Save stores to staging area and Commit moves to the final location. Two-stage commit scheme is used for not storing images which are uploaded but later never used in the comments, e.g. when somebody uploaded a picture but did not sent the comment.