-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtemplate.go
71 lines (56 loc) · 1013 Bytes
/
template.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package template
import "strings"
type MessageRetriever interface {
Message() string
}
type TheTemplate interface {
first() string
second() string
customStep(MessageRetriever) string
}
type Template struct{}
func (t *Template) first() string {
return "hello"
}
func (t *Template) second() string {
return "template"
}
func (t *Template) customStep(m MessageRetriever) string {
return strings.Join(
[]string{
t.first(),
m.Message(),
t.second(),
},
" ",
)
}
type Anonymous struct{}
func (a *Anonymous) first() string {
return "hello"
}
func (a *Anonymous) second() string {
return "template"
}
func (a *Anonymous) customStep(f func() string) string {
return strings.Join(
[]string{
a.first(),
f(),
a.second(),
},
" ",
)
}
type Wrapper struct {
myFunc func() string
}
func (a *Wrapper) Message() string {
if a.myFunc != nil {
return a.myFunc()
}
return ""
}
func MessageRetrieverAdapter(f func() string) MessageRetriever {
return &Wrapper{myFunc: f}
}