-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.go
36 lines (30 loc) · 926 Bytes
/
cron.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
package registry
import (
"reflect"
"strings"
"github.com/champly/hercules/configs"
"github.com/champly/hercules/servers"
)
func (s *ServiceRegistry) buildCronRouterByObj(pattern string, constrObj interface{}) {
routers, ok := s.services[configs.ServerTypeCron]
if !ok {
routers = []servers.Router{}
}
v := reflect.ValueOf(constrObj)
t := reflect.TypeOf(constrObj)
for i := 0; i < t.NumMethod(); i++ {
if strings.EqualFold(t.Method(i).Name, "Handler") {
routers = append(routers, servers.Router{Name: pattern, Handler: v.Method(i).Interface()})
break
}
}
s.services[configs.ServerTypeCron] = routers
}
func (s *ServiceRegistry) buildCronRouterByFunc(pattern string, f interface{}) {
routers, ok := s.services[configs.ServerTypeCron]
if !ok {
routers = []servers.Router{}
}
routers = append(routers, servers.Router{Name: pattern, Handler: f})
s.services[configs.ServerTypeCron] = routers
}