forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
directors.go
40 lines (31 loc) · 886 Bytes
/
directors.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
package repos
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
"github.com/cloudfoundry/bosh-cli/director"
)
type DirectorsRepo interface {
FindAll() ([]director.Director, error)
FindBySlug(string) (director.Director, error)
}
type directorsRepo struct {
directors []director.Director
logger boshlog.Logger
}
func NewDirectorsRepo(directors []director.Director, logger boshlog.Logger) DirectorsRepo {
return directorsRepo{
directors: directors,
logger: logger,
}
}
func (r directorsRepo) FindAll() ([]director.Director, error) {
return r.directors, nil
}
func (r directorsRepo) FindBySlug(slug string) (director.Director, error) {
for _, d := range r.directors {
if d.Source() == slug {
return d, nil
}
}
return director.Director{}, bosherr.Errorf("Director '%s' is not found", slug)
}