9
9
"github.com/go-chi/chi/v5"
10
10
"github.com/go-chi/render"
11
11
12
- "github.com/metacubex/mihomo/adapter"
13
12
"github.com/metacubex/mihomo/adapter/outboundgroup"
14
13
"github.com/metacubex/mihomo/common/utils"
15
14
"github.com/metacubex/mihomo/component/profile/cachefile"
@@ -32,7 +31,7 @@ func GroupRouter() http.Handler {
32
31
func getGroups (w http.ResponseWriter , r * http.Request ) {
33
32
var gs []C.Proxy
34
33
for _ , p := range tunnel .Proxies () {
35
- if _ , ok := p .( * adapter. Proxy ). ProxyAdapter .(C.Group ); ok {
34
+ if _ , ok := p .Adapter () .(C.Group ); ok {
36
35
gs = append (gs , p )
37
36
}
38
37
}
@@ -43,7 +42,7 @@ func getGroups(w http.ResponseWriter, r *http.Request) {
43
42
44
43
func getGroup (w http.ResponseWriter , r * http.Request ) {
45
44
proxy := r .Context ().Value (CtxKeyProxy ).(C.Proxy )
46
- if _ , ok := proxy .( * adapter. Proxy ). ProxyAdapter .(C.Group ); ok {
45
+ if _ , ok := proxy .Adapter () .(C.Group ); ok {
47
46
render .JSON (w , r , proxy )
48
47
return
49
48
}
@@ -53,25 +52,15 @@ func getGroup(w http.ResponseWriter, r *http.Request) {
53
52
54
53
func getGroupDelay (w http.ResponseWriter , r * http.Request ) {
55
54
proxy := r .Context ().Value (CtxKeyProxy ).(C.Proxy )
56
- group , ok := proxy .( * adapter. Proxy ). ProxyAdapter .(C.Group )
55
+ group , ok := proxy .Adapter () .(C.Group )
57
56
if ! ok {
58
57
render .Status (r , http .StatusNotFound )
59
58
render .JSON (w , r , ErrNotFound )
60
59
return
61
60
}
62
61
63
- switch proxy .(* adapter.Proxy ).Type () {
64
- case C .URLTest :
65
- if urlTestGroup , ok := proxy .(* adapter.Proxy ).ProxyAdapter .(* outboundgroup.URLTest ); ok {
66
- urlTestGroup .ForceSet ("" )
67
- }
68
- case C .Fallback :
69
- if fallbackGroup , ok := proxy .(* adapter.Proxy ).ProxyAdapter .(* outboundgroup.Fallback ); ok {
70
- fallbackGroup .ForceSet ("" )
71
- }
72
- }
73
-
74
- if proxy .(* adapter.Proxy ).Type () != C .Selector {
62
+ if selectAble , ok := proxy .Adapter ().(outboundgroup.SelectAble ); ok && proxy .Type () != C .Selector {
63
+ selectAble .ForceSet ("" )
75
64
cachefile .Cache ().SetSelected (proxy .Name (), "" )
76
65
}
77
66
0 commit comments