-
Notifications
You must be signed in to change notification settings - Fork 682
/
source.go
45 lines (36 loc) · 873 Bytes
/
source.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
package gateway
import (
"fmt"
"github.com/datawire/ambassador/v2/pkg/kates"
)
type Source interface {
Location() string
}
type k8sSource struct {
resource kates.Object
}
func (s *k8sSource) Location() string {
return fmt.Sprintf("%s %s.%s", s.resource.GetObjectKind().GroupVersionKind().Kind, s.resource.GetName(), s.resource.GetNamespace())
}
func SourceFromResource(resource kates.Object) Source {
return &k8sSource{resource}
}
type patternSource struct {
pattern string
args []interface{}
}
func Sourcef(pattern string, args ...interface{}) Source {
return &patternSource{pattern, args}
}
func (c *patternSource) Location() string {
var args []interface{}
for _, a := range c.args {
switch s := a.(type) {
case Source:
args = append(args, s.Location())
default:
args = append(args, a)
}
}
return fmt.Sprintf(c.pattern, args...)
}