...
1 package gateway
2
3 import (
4 "fmt"
5
6 "github.com/emissary-ingress/emissary/v3/pkg/kates"
7 )
8
9 type Source interface {
10 Location() string
11 }
12
13 type k8sSource struct {
14 resource kates.Object
15 }
16
17 func (s *k8sSource) Location() string {
18 return fmt.Sprintf("%s %s.%s", s.resource.GetObjectKind().GroupVersionKind().Kind, s.resource.GetName(), s.resource.GetNamespace())
19 }
20
21 func SourceFromResource(resource kates.Object) Source {
22 return &k8sSource{resource}
23 }
24
25 type patternSource struct {
26 pattern string
27 args []interface{}
28 }
29
30 func Sourcef(pattern string, args ...interface{}) Source {
31 return &patternSource{pattern, args}
32 }
33
34 func (c *patternSource) Location() string {
35 var args []interface{}
36 for _, a := range c.args {
37 switch s := a.(type) {
38 case Source:
39 args = append(args, s.Location())
40 default:
41 args = append(args, a)
42 }
43 }
44 return fmt.Sprintf(c.pattern, args...)
45 }
46
View as plain text