Documentation
¶
Index ¶
- Variables
- func HandleImage(cache *ImageCache) http.HandlerFunc
- type ImageCache
- func (c *ImageCache) GetAvatar(ctx context.Context, key string, buf *bytes.Buffer) error
- func (c *ImageCache) GetImage(ctx context.Context, key string, buf *bytes.Buffer) error
- func (c *ImageCache) GetScreenshot(ctx context.Context, key string, buf *bytes.Buffer) error
- func (c *ImageCache) GetThumbnail(ctx context.Context, key string, buf *bytes.Buffer) error
- func (c *ImageCache) SaveAvatar(ctx context.Context, id string, data []byte) error
- func (c *ImageCache) SaveImage(ctx context.Context, id string, data []byte) error
- func (c *ImageCache) SaveScreenshot(ctx context.Context, id string, data []byte) error
- func (c *ImageCache) SaveThumbnail(ctx context.Context, id string, data []byte) error
- type ObjectCache
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrCacheNotFound = errors.New("cache not found")
View Source
var NewCache = sync.OnceValues(func() (*ImageCache, error) { appCfg, err := config.LoadAppConfig() if err != nil { return nil, fmt.Errorf("load app config: %w", err) } c := &ImageCache{ caches: make(map[string]ObjectCache), } switch appCfg.GetAppEnvironment() { case config.EnvProduction: bucketName := os.Getenv("IMAGEPROXY_BUCKET") imgCache, err := gcs.Connect(context.Background(), bucketName, "") if err != nil { return nil, fmt.Errorf("connect to gcs:%s %w", bucketName, err) } c.caches["imgproxy"] = imgCache avatarCache, err := gcs.Connect(context.Background(), bucketName, "avatars") if err != nil { return nil, fmt.Errorf("connect to gcs:%s/%s %w", bucketName, "avatars", err) } c.caches["avatars"] = avatarCache thumbnailCache, err := gcs.Connect(context.Background(), bucketName, "subscription_images") if err != nil { return nil, fmt.Errorf("connect to gcs:%s/%s %w", bucketName, "subscription_images", err) } c.caches["subscription_thumbnails"] = thumbnailCache screenshotCache, err := gcs.Connect(context.Background(), bucketName, "screenshots") if err != nil { return nil, fmt.Errorf("connect to gcs:%s/%s %w", bucketName, "screenshots", err) } c.caches["screenshots"] = screenshotCache default: var err error imgCache, err := newDirCache("imgproxy") if err != nil { return nil, fmt.Errorf("create dir cache: %s: %w", "imgproxy", err) } c.caches["imgproxy"] = imgCache avatarCache, err := newDirCache("avatars") if err != nil { return nil, fmt.Errorf("create dir cache: %s: %w", "avatars", err) } c.caches["avatars"] = avatarCache thumbnailCache, err := newDirCache("subscription_images") if err != nil { return nil, fmt.Errorf("create dir cache: %s: %w", "subscription_images", err) } c.caches["subscription_thumbnails"] = thumbnailCache screenshotsCache, err := newDirCache("screenshots") if err != nil { return nil, fmt.Errorf("create dir cache: %s: %w", "screenshots", err) } c.caches["screenshots"] = screenshotsCache } return c, nil })
View Source
var NewItemsCache = sync.OnceValues(func() (ObjectCache, error) { appCfg, err := config.LoadAppConfig() if err != nil { return nil, fmt.Errorf("load app config: %w", err) } switch appCfg.GetAppEnvironment() { case config.EnvProduction: bucketName := os.Getenv("FORAGD_SERVER_BUCKET") var err error itemsCache, err := gcs.Connect(context.Background(), bucketName, "articles") if err != nil { return nil, fmt.Errorf("connect to gcs:%s: %w", "articles", err) } return itemsCache, nil default: var err error itemsCache, err := newDirCache("articles") if err != nil { return nil, fmt.Errorf("create items dir cache: %w", err) } return itemsCache, nil } })
Functions ¶
func HandleImage ¶
func HandleImage(cache *ImageCache) http.HandlerFunc
HandleImage handles fetching and displaying an image from one of the image caches.
Types ¶
type ImageCache ¶ added in v0.235.0
type ImageCache struct {
// contains filtered or unexported fields
}
func (*ImageCache) GetScreenshot ¶ added in v0.235.0
func (*ImageCache) GetThumbnail ¶ added in v0.235.0
func (*ImageCache) SaveAvatar ¶ added in v0.235.0
func (*ImageCache) SaveScreenshot ¶ added in v0.235.0
func (*ImageCache) SaveThumbnail ¶ added in v0.235.0
Click to show internal directories.
Click to hide internal directories.