Eric Bower
ยท
2025-04-18
memory.go
1package storage
2
3import (
4 "io"
5 "net/http"
6 "time"
7
8 sst "github.com/picosh/pico/pkg/pobj/storage"
9 "github.com/picosh/pico/pkg/shared/mime"
10)
11
12type StorageMemory struct {
13 *sst.StorageMemory
14}
15
16func NewStorageMemory(sto map[string]map[string]string) (*StorageMemory, error) {
17 st, err := sst.NewStorageMemory(sto)
18 if err != nil {
19 return nil, err
20 }
21 return &StorageMemory{st}, nil
22}
23
24func (s *StorageMemory) ServeObject(bucket sst.Bucket, fpath string, opts *ImgProcessOpts) (io.ReadCloser, *sst.ObjectInfo, error) {
25 obj, info, err := s.GetObject(bucket, fpath)
26 if info.Metadata == nil {
27 info.Metadata = make(http.Header)
28 }
29 // Make tests work by supplying non-null Last-Modified and Etag values
30 if info.LastModified.IsZero() {
31 info.LastModified = time.Now().UTC()
32 }
33 if info.ETag == "" {
34 info.ETag = "static-etag-for-testing-purposes"
35 }
36 mimeType := mime.GetMimeType(fpath)
37 info.Metadata.Set("content-type", mimeType)
38 return obj, info, err
39}