-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-IHealthServer.go
288 lines (251 loc) · 11.3 KB
/
gen-IHealthServer.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny
package core
import (
"reflect"
"strings"
di "github.com/fluffy-bunny/sarulabsdi"
"github.com/rs/zerolog/log"
)
// ReflectTypeIHealthServer used when your service claims to implement IHealthServer
var ReflectTypeIHealthServer = di.GetInterfaceReflectType((*IHealthServer)(nil))
// AddSingletonIHealthServer adds a type that implements IHealthServer
func AddSingletonIHealthServer(builder *di.Builder, implType reflect.Type, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("SINGLETON", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "type",
})
di.AddSingleton(builder, implType, implementedTypes...)
}
// AddSingletonIHealthServerWithMetadata adds a type that implements IHealthServer
func AddSingletonIHealthServerWithMetadata(builder *di.Builder, implType reflect.Type, metaData map[string]interface{}, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("SINGLETON", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "type",
},
_logIHealthServerExtra{
Name: "DI-M",
Value: metaData,
})
di.AddSingletonWithMetadata(builder, implType, metaData, implementedTypes...)
}
// AddSingletonIHealthServerByObj adds a prebuilt obj
func AddSingletonIHealthServerByObj(builder *di.Builder, obj interface{}, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("SINGLETON", reflect.TypeOf(obj), _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "obj",
})
di.AddSingletonWithImplementedTypesByObj(builder, obj, implementedTypes...)
}
// AddSingletonIHealthServerByObjWithMetadata adds a prebuilt obj
func AddSingletonIHealthServerByObjWithMetadata(builder *di.Builder, obj interface{}, metaData map[string]interface{}, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("SINGLETON", reflect.TypeOf(obj), _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "obj",
},
_logIHealthServerExtra{
Name: "DI-M",
Value: metaData,
})
di.AddSingletonWithImplementedTypesByObjWithMetadata(builder, obj, metaData, implementedTypes...)
}
// AddSingletonIHealthServerByFunc adds a type by a custom func
func AddSingletonIHealthServerByFunc(builder *di.Builder, implType reflect.Type, build func(ctn di.Container) (interface{}, error), implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("SINGLETON", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "func",
})
di.AddSingletonWithImplementedTypesByFunc(builder, implType, build, implementedTypes...)
}
// AddSingletonIHealthServerByFuncWithMetadata adds a type by a custom func
func AddSingletonIHealthServerByFuncWithMetadata(builder *di.Builder, implType reflect.Type, build func(ctn di.Container) (interface{}, error), metaData map[string]interface{}, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("SINGLETON", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "func",
},
_logIHealthServerExtra{
Name: "DI-M",
Value: metaData,
})
di.AddSingletonWithImplementedTypesByFuncWithMetadata(builder, implType, build, metaData, implementedTypes...)
}
// AddTransientIHealthServer adds a type that implements IHealthServer
func AddTransientIHealthServer(builder *di.Builder, implType reflect.Type, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("TRANSIENT", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "type",
})
di.AddTransientWithImplementedTypes(builder, implType, implementedTypes...)
}
// AddTransientIHealthServerWithMetadata adds a type that implements IHealthServer
func AddTransientIHealthServerWithMetadata(builder *di.Builder, implType reflect.Type, metaData map[string]interface{}, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("TRANSIENT", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "type",
},
_logIHealthServerExtra{
Name: "DI-M",
Value: metaData,
})
di.AddTransientWithImplementedTypesWithMetadata(builder, implType, metaData, implementedTypes...)
}
// AddTransientIHealthServerByFunc adds a type by a custom func
func AddTransientIHealthServerByFunc(builder *di.Builder, implType reflect.Type, build func(ctn di.Container) (interface{}, error), implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("TRANSIENT", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "func",
})
di.AddTransientWithImplementedTypesByFunc(builder, implType, build, implementedTypes...)
}
// AddTransientIHealthServerByFuncWithMetadata adds a type by a custom func
func AddTransientIHealthServerByFuncWithMetadata(builder *di.Builder, implType reflect.Type, build func(ctn di.Container) (interface{}, error), metaData map[string]interface{}, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("TRANSIENT", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "func",
},
_logIHealthServerExtra{
Name: "DI-M",
Value: metaData,
})
di.AddTransientWithImplementedTypesByFuncWithMetadata(builder, implType, build, metaData, implementedTypes...)
}
// AddScopedIHealthServer adds a type that implements IHealthServer
func AddScopedIHealthServer(builder *di.Builder, implType reflect.Type, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("SCOPED", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "type",
})
di.AddScopedWithImplementedTypes(builder, implType, implementedTypes...)
}
// AddScopedIHealthServerWithMetadata adds a type that implements IHealthServer
func AddScopedIHealthServerWithMetadata(builder *di.Builder, implType reflect.Type, metaData map[string]interface{}, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("SCOPED", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "type",
},
_logIHealthServerExtra{
Name: "DI-M",
Value: metaData,
})
di.AddScopedWithImplementedTypesWithMetadata(builder, implType, metaData, implementedTypes...)
}
// AddScopedIHealthServerByFunc adds a type by a custom func
func AddScopedIHealthServerByFunc(builder *di.Builder, implType reflect.Type, build func(ctn di.Container) (interface{}, error), implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("SCOPED", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "func",
})
di.AddScopedWithImplementedTypesByFunc(builder, implType, build, implementedTypes...)
}
// AddScopedIHealthServerByFuncWithMetadata adds a type by a custom func
func AddScopedIHealthServerByFuncWithMetadata(builder *di.Builder, implType reflect.Type, build func(ctn di.Container) (interface{}, error), metaData map[string]interface{}, implementedTypes ...reflect.Type) {
implementedTypes = append(implementedTypes, ReflectTypeIHealthServer)
_logAddIHealthServer("SCOPED", implType, _getImplementedIHealthServerNames(implementedTypes...),
_logIHealthServerExtra{
Name: "DI-BY",
Value: "func",
},
_logIHealthServerExtra{
Name: "DI-M",
Value: metaData,
})
di.AddScopedWithImplementedTypesByFuncWithMetadata(builder, implType, build, metaData, implementedTypes...)
}
// RemoveAllIHealthServer removes all IHealthServer from the DI
func RemoveAllIHealthServer(builder *di.Builder) {
builder.RemoveAllByType(ReflectTypeIHealthServer)
}
// GetIHealthServerFromContainer alternative to SafeGetIHealthServerFromContainer but panics of object is not present
func GetIHealthServerFromContainer(ctn di.Container) IHealthServer {
return ctn.GetByType(ReflectTypeIHealthServer).(IHealthServer)
}
// GetManyIHealthServerFromContainer alternative to SafeGetManyIHealthServerFromContainer but panics of object is not present
func GetManyIHealthServerFromContainer(ctn di.Container) []IHealthServer {
objs := ctn.GetManyByType(ReflectTypeIHealthServer)
var results []IHealthServer
for _, obj := range objs {
results = append(results, obj.(IHealthServer))
}
return results
}
// SafeGetIHealthServerFromContainer trys to get the object by type, will not panic, returns nil and error
func SafeGetIHealthServerFromContainer(ctn di.Container) (IHealthServer, error) {
obj, err := ctn.SafeGetByType(ReflectTypeIHealthServer)
if err != nil {
return nil, err
}
return obj.(IHealthServer), nil
}
// GetIHealthServerDefinition returns that last definition registered that this container can provide
func GetIHealthServerDefinition(ctn di.Container) *di.Def {
def := ctn.GetDefinitionByType(ReflectTypeIHealthServer)
return def
}
// GetIHealthServerDefinitions returns all definitions that this container can provide
func GetIHealthServerDefinitions(ctn di.Container) []*di.Def {
defs := ctn.GetDefinitionsByType(ReflectTypeIHealthServer)
return defs
}
// SafeGetManyIHealthServerFromContainer trys to get the object by type, will not panic, returns nil and error
func SafeGetManyIHealthServerFromContainer(ctn di.Container) ([]IHealthServer, error) {
objs, err := ctn.SafeGetManyByType(ReflectTypeIHealthServer)
if err != nil {
return nil, err
}
var results []IHealthServer
for _, obj := range objs {
results = append(results, obj.(IHealthServer))
}
return results, nil
}
type _logIHealthServerExtra struct {
Name string
Value interface{}
}
func _logAddIHealthServer(scopeType string, implType reflect.Type, interfaces string, extra ..._logIHealthServerExtra) {
infoEvent := log.Info().
Str("DI", scopeType).
Str("DI-I", interfaces).
Str("DI-B", implType.Elem().String())
for _, extra := range extra {
infoEvent = infoEvent.Interface(extra.Name, extra.Value)
}
infoEvent.Send()
}
func _getImplementedIHealthServerNames(implementedTypes ...reflect.Type) string {
builder := strings.Builder{}
for idx, implementedType := range implementedTypes {
builder.WriteString(implementedType.Name())
if idx < len(implementedTypes)-1 {
builder.WriteString(", ")
}
}
return builder.String()
}