-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlens.go
210 lines (165 loc) · 5.86 KB
/
lens.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package scene
import (
"fmt"
"strings"
)
// Lens is an alias for Module
// Module Component
type Application interface {
Name() ImplName // return scene
//Status() AppStatus
//Error() error
}
type Repository interface {
RepoImplName() ImplName
}
type Service interface {
SrvImplName() ImplName
}
// Lens Definition
type ModuleName string
func (l ModuleName) String() string {
return string(l)
}
func (l ModuleName) TableName(table string) string {
return string(l) + "_" + table
}
func (l ModuleName) ImplName(iface, implementation string) ImplName {
return NewImplName(ImplTypeModule, string(l), iface, implementation)
}
func (l ModuleName) ImplNameNoVer(implementation string) ImplName {
return NewImplNameNoVer(ImplTypeModule, string(l), implementation)
}
type InfraName string
func (i InfraName) String() string {
return string(i)
}
func (i InfraName) ImplName(implementation, version string) ImplName {
return NewImplName(ImplTypeInfra, string(i), implementation, version)
}
func (i InfraName) ImplNameNoVer(implementation string) ImplName {
return NewImplNameNoVer(ImplTypeInfra, string(i), implementation)
}
type CompositionName string
func (c CompositionName) String() string {
return string(c)
}
func (c CompositionName) ImplName(implementation, version string) ImplName {
return NewImplName(ImplTypeComp, string(c), implementation, version)
}
func (c CompositionName) ImplNameNoVer(implementation string) ImplName {
return NewImplNameNoVer(ImplTypeComp, string(c), implementation)
}
/*
ImplName is the name of an implementation.
It is used to identify an implementation of a repository, service or application.
*/
type ImplType string
const (
ImplTypeCore = ImplType("core") // core type
ImplTypeScene = ImplType("scene") // scenario type
ImplTypeInfra = ImplType("infra") // infrastructure type
ImplTypeComp = ImplType("composite") // composition type
ImplTypeModule = ImplType("module") // module type
// Deprecated
ImplTypeRepo = ImplType("repo") // module repository type
// Deprecated
ImplTypeSrv = ImplType("srv") // module service type
// Deprecated
ImplTypeApp = ImplType("app") // module application type
)
type Named interface {
ImplName() ImplName
}
type ImplName struct {
ImplType ImplType
Module string
Interface string
Implementation string
}
// String returns a string representation of the implementation name.
// String is a pretty representation of the implementation name.
// If you want to use the implementation name as an identifier, use Identifier().
func (i ImplName) String() string {
if i.Implementation == "" {
return fmt.Sprintf("(%s)%s:%s", string(i.ImplType), i.Module, i.Interface)
}
return fmt.Sprintf("(%s)%s:%s:%s", string(i.ImplType), i.Module, i.Interface, i.Implementation)
}
func (i ImplName) EndpointName() string {
return i.Module + "/" + i.Interface
}
// Identifier returns a string identifier of the implementation name.
func (i ImplName) Identifier() string {
return fmt.Sprintf("(%s)%s:%s:%s", string(i.ImplType), i.Module, i.Interface, i.Implementation)
}
// ExportName return interface name with capitalized module name
func (i ImplName) ExportName() string {
return fmt.Sprintf(strings.ToUpper(i.Module[:1]) + i.Module[1:] + "." + i.Interface)
}
func NewImplName(implType ImplType, module, implementation, version string) ImplName {
return ImplName{
ImplType: implType,
Module: module,
Interface: implementation,
Implementation: version,
}
}
func NewImplNameNoVer(implType ImplType, module, iface string) ImplName {
return ImplName{
ImplType: implType,
Module: module,
Interface: iface,
Implementation: "default",
}
}
func NewSceneImplName(module, iface, version string) ImplName {
return NewImplName(ImplTypeScene, module, iface, version)
}
func NewSceneImplNameNoVer(module, iface string) ImplName {
return NewImplNameNoVer(ImplTypeScene, module, iface)
}
func NewCoreImplName(module, iface, version string) ImplName {
return NewImplName(ImplTypeCore, module, iface, version)
}
func NewCoreImplNameNoVer(module, iface string) ImplName {
return NewImplNameNoVer(ImplTypeCore, module, iface)
}
func NewModuleImplName(module, iface, implementation string) ImplName {
return NewImplName(ImplTypeModule, module, iface, implementation)
}
func NewModuleImplNameNoVer(module, iface string) ImplName {
return NewImplNameNoVer(ImplTypeModule, module, iface)
}
func NewInfraImplName(module, iface, implementation string) ImplName {
return NewImplName(ImplTypeInfra, module, iface, implementation)
}
func NewInfraImplNameNoVer(module, iface string) ImplName {
return NewImplNameNoVer(ImplTypeInfra, module, iface)
}
// NewModuleImplName creates a new module implementation name.
// Deprecated: use NewModuleImplNameNoVer instead
func NewAppImplName(module, implementation, version string) ImplName {
return NewImplName(ImplTypeApp, module, implementation, version)
}
// NewModuleImplName creates a new module implementation name.
// Deprecated: use NewModuleImplNameNoVer instead
func NewAppImplNameNoVer(module, implementation string) ImplName {
return NewImplNameNoVer(ImplTypeApp, module, implementation)
}
// Deprecated: use NewModuleImplNameNoVer instead
func NewSrvImplName(module, implementation, version string) ImplName {
return NewImplName(ImplTypeSrv, module, implementation, version)
}
// Deprecated: use NewModuleImplNameNoVer instead
func NewSrvImplNameNoVer(module, implementation string) ImplName {
return NewImplNameNoVer(ImplTypeSrv, module, implementation)
}
// Deprecated: use NewModuleImplNameNoVer instead
func NewRepoImplName(module, implementation, version string) ImplName {
return NewImplName(ImplTypeRepo, module, implementation, version)
}
// Deprecated: use NewModuleImplNameNoVer instead
func NewRepoImplNameNoVer(module, implementation string) ImplName {
return NewImplNameNoVer(ImplTypeRepo, module, implementation)
}