-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistry.go
56 lines (45 loc) · 1.27 KB
/
registry.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
package registry
import (
"github.com/champly/hercules/ctxs/component"
"github.com/champly/hercules/servers"
)
type IServiceRegistry interface {
API(pattern string, handle interface{})
Cron(name string, handle interface{})
MQ(name string, handle interface{})
GetRouters(st string) []servers.Router
}
type ServiceRegistry struct {
services map[string][]servers.Router
toolBox component.IToolBox
}
func NewServiceRegistry() *ServiceRegistry {
return &ServiceRegistry{services: make(map[string][]servers.Router), toolBox: component.NewToolBox()}
}
func (s *ServiceRegistry) API(pattern string, r interface{}) {
constructor, ok := r.(func() interface{})
if ok {
s.buildAPIRouterByObj(pattern, constructor())
return
}
s.buildAPIRouterByFunc(pattern, r)
}
func (s *ServiceRegistry) Cron(pattern string, r interface{}) {
constructor, ok := r.(func() interface{})
if ok {
s.buildCronRouterByObj(pattern, constructor())
return
}
s.buildCronRouterByFunc(pattern, r)
}
func (s *ServiceRegistry) MQ(pattern string, r interface{}) {
constructor, ok := r.(func() interface{})
if ok {
s.buildMQRouterByObj(pattern, constructor())
return
}
s.buildMQRouterByFunc(pattern, r)
}
func (s *ServiceRegistry) GetRouters(st string) []servers.Router {
return s.services[st]
}