-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
facade.go
46 lines (36 loc) · 945 Bytes
/
facade.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 source
import (
"context"
"github.com/YuukanOO/seelf/internal/deployment/domain"
)
type (
Source interface {
domain.Source
CanPrepare(any) bool
CanFetch(domain.SourceData) bool
}
facade struct {
sources []Source
}
)
// Creates a new facade which will call the appropriate source when calling Fetch or Prepare.
func NewFacade(sources ...Source) domain.Source {
return &facade{sources}
}
func (r *facade) Prepare(app domain.App, payload any) (domain.SourceData, error) {
for _, src := range r.sources {
if src.CanPrepare(payload) {
return src.Prepare(app, payload)
}
}
return nil, domain.ErrNoValidSourceFound
}
func (r *facade) Fetch(ctx context.Context, dir string, logger domain.DeploymentLogger, depl domain.Deployment) error {
meta := depl.Source()
for _, src := range r.sources {
if src.CanFetch(meta) {
return src.Fetch(ctx, dir, logger, depl)
}
}
return domain.ErrNoValidSourceFound
}