-
Notifications
You must be signed in to change notification settings - Fork 0
/
cyber.go
58 lines (50 loc) · 2.32 KB
/
cyber.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
package cyber
import (
"reflect"
"github.com/haormj/cyber/common"
"github.com/haormj/cyber/component"
"github.com/haormj/cyber/pb"
"google.golang.org/protobuf/proto"
)
func RegisterTimerComponent(name string, c component.Component) bool {
component.ComponentMap.Store(name, component.StartTimerComponent(func(config *pb.TimerComponentConfig) bool {
com := component.NewTimerComponent(common.ZeroByType(reflect.TypeOf(c)).Interface().(component.Component))
return com.Initialize(config)
}))
return true
}
func RegisterComponent(name string, c component.Component) bool {
component.ComponentMap.Store(name, component.StartComponent(func(config *pb.ComponentConfig) bool {
com := component.NewDataDrivenComponent(common.ZeroByType(reflect.TypeOf(c)).Interface().(component.Component))
return com.Initialize(config)
}))
return true
}
func RegisterComponent1[M proto.Message](name string, c component.Component1[M]) bool {
component.ComponentMap.Store(name, component.StartComponent(func(config *pb.ComponentConfig) bool {
com := component.NewDataDrivenComponent1(common.ZeroByType(reflect.TypeOf(c)).Interface().(component.Component1[M]))
return com.Initialize(config)
}))
return true
}
func RegisterComponent2[M0, M1 proto.Message](name string, c component.Component2[M0, M1]) bool {
component.ComponentMap.Store(name, component.StartComponent(func(config *pb.ComponentConfig) bool {
com := component.NewDataDrivenComponent2(common.ZeroByType(reflect.TypeOf(c)).Interface().(component.Component2[M0, M1]))
return com.Initialize(config)
}))
return true
}
func RegisterComponent3[M0, M1, M2 proto.Message](name string, c component.Component3[M0, M1, M2]) bool {
component.ComponentMap.Store(name, component.StartComponent(func(config *pb.ComponentConfig) bool {
com := component.NewDataDrivenComponent3(common.ZeroByType(reflect.TypeOf(c)).Interface().(component.Component3[M0, M1, M2]))
return com.Initialize(config)
}))
return true
}
func RegisterComponent4[M0, M1, M2, M3 proto.Message](name string, c component.Component4[M0, M1, M2, M3]) bool {
component.ComponentMap.Store(name, component.StartComponent(func(config *pb.ComponentConfig) bool {
com := component.NewDataDrivenComponent4(common.ZeroByType(reflect.TypeOf(c)).Interface().(component.Component4[M0, M1, M2, M3]))
return com.Initialize(config)
}))
return true
}