-
Notifications
You must be signed in to change notification settings - Fork 110
/
discovery.go
43 lines (35 loc) · 1.22 KB
/
discovery.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
package resource
import (
"context"
"fmt"
"github.com/edaniels/golog"
)
type (
// DiscoveryQuery is a tuple of API and model used to lookup discovery functions.
DiscoveryQuery struct {
API API
Model Model
}
// DiscoveryFunc is a function that discovers component configurations.
DiscoveryFunc func(ctx context.Context, logger golog.Logger) (interface{}, error)
// Discovery holds a Query and a corresponding discovered component configuration. A
// discovered component configuration can be comprised of primitives, a list of
// primitives, maps with string keys (or at least can be decomposed into one), or
// lists of the forementioned type of maps. Results with other types of data are not
// guaranteed.
Discovery struct {
Query DiscoveryQuery
Results interface{}
}
// DiscoverError indicates that a Discover function has returned an error.
DiscoverError struct {
Query DiscoveryQuery
}
)
func (e *DiscoverError) Error() string {
return fmt.Sprintf("failed to get discovery for api %q and model %q", e.Query.API, e.Query.Model)
}
// NewDiscoveryQuery returns a discovery query for a given API and model.
func NewDiscoveryQuery(api API, model Model) DiscoveryQuery {
return DiscoveryQuery{api, model}
}