-
Notifications
You must be signed in to change notification settings - Fork 112
/
default.go
121 lines (103 loc) · 3.97 KB
/
default.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
package motan
import (
"net/http"
"sync"
motan "github.com/weibocom/motan-go/core"
"github.com/weibocom/motan-go/endpoint"
"github.com/weibocom/motan-go/filter"
"github.com/weibocom/motan-go/ha"
"github.com/weibocom/motan-go/lb"
"github.com/weibocom/motan-go/provider"
"github.com/weibocom/motan-go/registry"
"github.com/weibocom/motan-go/serialize"
"github.com/weibocom/motan-go/server"
)
var (
extOnce sync.Once
handlerOnce sync.Once
defaultExtFactory *motan.DefaultExtensionFactory
// all default manage handlers
defaultManageHandlers map[string]http.Handler
// PermissionCheck is default permission check for manage request
PermissionCheck = NoPermissionCheck
)
type PermissionCheckFunc func(r *http.Request) bool
func NoPermissionCheck(r *http.Request) bool {
return true
}
func GetDefaultManageHandlers() map[string]http.Handler {
handlerOnce.Do(func() {
defaultManageHandlers = make(map[string]http.Handler, 16)
status := &StatusHandler{}
defaultManageHandlers["/"] = status
defaultManageHandlers["/200"] = status
defaultManageHandlers["/503"] = status
defaultManageHandlers["/version"] = status
defaultManageHandlers["/status"] = status
defaultManageHandlers["/registry/status"] = status
info := &InfoHandler{}
defaultManageHandlers["/getConfig"] = info
defaultManageHandlers["/getReferService"] = info
defaultManageHandlers["/getAllService"] = info
debug := &DebugHandler{}
defaultManageHandlers["/debug/pprof/"] = debug
defaultManageHandlers["/debug/pprof/cmdline"] = debug
defaultManageHandlers["/debug/pprof/profile"] = debug
defaultManageHandlers["/debug/pprof/symbol"] = debug
defaultManageHandlers["/debug/pprof/trace"] = debug
defaultManageHandlers["/debug/mesh/trace"] = debug
defaultManageHandlers["/debug/pprof/sw"] = debug
defaultManageHandlers["/debug/stat/system"] = debug
defaultManageHandlers["/debug/stat/process"] = debug
defaultManageHandlers["/debug/stat/openFiles"] = debug
defaultManageHandlers["/debug/stat/connections"] = debug
defaultManageHandlers["/debug/pprof/allocs"] = debug
defaultManageHandlers["/debug/pprof/block"] = debug
defaultManageHandlers["/debug/pprof/goroutine"] = debug
defaultManageHandlers["/debug/pprof/mutex"] = debug
defaultManageHandlers["/debug/pprof/heap"] = debug
switcher := &SwitcherHandler{}
defaultManageHandlers["/switcher/set"] = switcher
defaultManageHandlers["/switcher/get"] = switcher
defaultManageHandlers["/switcher/getAll"] = switcher
log := &LogHandler{}
defaultManageHandlers["/logConfig/get"] = log
defaultManageHandlers["/logConfig/set"] = log
dynamicConfigurer := &DynamicConfigurerHandler{}
defaultManageHandlers["/registry/register"] = dynamicConfigurer
defaultManageHandlers["/registry/unregister"] = dynamicConfigurer
defaultManageHandlers["/registry/subscribe"] = dynamicConfigurer
defaultManageHandlers["/registry/list"] = dynamicConfigurer
defaultManageHandlers["/registry/info"] = dynamicConfigurer
metaInfo := &MetaInfo{}
defaultManageHandlers["/meta/update"] = metaInfo
defaultManageHandlers["/meta/delete"] = metaInfo
defaultManageHandlers["/meta/get"] = metaInfo
defaultManageHandlers["/meta/getAll"] = metaInfo
hotReload := &HotReload{}
defaultManageHandlers["/reload/clusters"] = hotReload
runtimeHandler := &RuntimeHandler{}
defaultManageHandlers["/runtime/info"] = runtimeHandler
})
return defaultManageHandlers
}
func GetDefaultExtFactory() motan.ExtensionFactory {
extOnce.Do(func() {
defaultExtFactory = &motan.DefaultExtensionFactory{}
defaultExtFactory.Initialize()
AddDefaultExt(defaultExtFactory)
})
return defaultExtFactory
}
func AddDefaultExt(d motan.ExtensionFactory) {
// all default extension
filter.RegistDefaultFilters(d)
ha.RegistDefaultHa(d)
lb.RegistDefaultLb(d)
endpoint.RegistDefaultEndpoint(d)
provider.RegistDefaultProvider(d)
registry.RegistDefaultRegistry(d)
server.RegistDefaultServers(d)
server.RegistDefaultMessageHandlers(d)
serialize.RegistDefaultSerializations(d)
}