/
storage.go
46 lines (37 loc) · 914 Bytes
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package storage
import (
"context"
"io/fs"
"net/http"
"sigs.k8s.io/controller-runtime/pkg/client"
)
type Storage interface {
Loader
Storer
}
type Loader interface {
Load(ctx context.Context, owner client.Object) (fs.FS, error)
}
type Storer interface {
Store(ctx context.Context, owner client.Object, bundle fs.FS) error
Delete(ctx context.Context, owner client.Object) error
http.Handler
URLFor(ctx context.Context, owner client.Object) (string, error)
}
type fallbackLoaderStorage struct {
Storage
fallbackLoader Loader
}
func WithFallbackLoader(s Storage, fallback Loader) Storage {
return &fallbackLoaderStorage{
Storage: s,
fallbackLoader: fallback,
}
}
func (s *fallbackLoaderStorage) Load(ctx context.Context, owner client.Object) (fs.FS, error) {
fsys, err := s.Storage.Load(ctx, owner)
if err != nil {
return s.fallbackLoader.Load(ctx, owner)
}
return fsys, nil
}