chore: return more information for the api

This commit is contained in:
xishang0128 2024-01-07 23:32:22 +08:00
parent 7e3e38d054
commit ffcd672ebf
No known key found for this signature in database
GPG Key ID: 44A1E10B5ADF68CB
6 changed files with 38 additions and 5 deletions

View File

@ -21,6 +21,8 @@ type Fallback struct {
testUrl string testUrl string
selected string selected string
expectedStatus string expectedStatus string
Hidden bool
Icon string
} }
func (f *Fallback) Now() string { func (f *Fallback) Now() string {
@ -90,6 +92,8 @@ func (f *Fallback) MarshalJSON() ([]byte, error) {
"testUrl": f.testUrl, "testUrl": f.testUrl,
"expectedStatus": f.expectedStatus, "expectedStatus": f.expectedStatus,
"fixed": f.selected, "fixed": f.selected,
"hidden": f.Hidden,
"icon": f.Icon,
}) })
} }
@ -165,5 +169,7 @@ func NewFallback(option *GroupCommonOption, providers []provider.ProxyProvider)
disableUDP: option.DisableUDP, disableUDP: option.DisableUDP,
testUrl: option.URL, testUrl: option.URL,
expectedStatus: option.ExpectedStatus, expectedStatus: option.ExpectedStatus,
Hidden: option.Hidden,
Icon: option.Icon,
} }
} }

View File

@ -29,6 +29,8 @@ type LoadBalance struct {
strategyFn strategyFn strategyFn strategyFn
testUrl string testUrl string
expectedStatus string expectedStatus string
Hidden bool
Icon string
} }
var errStrategy = errors.New("unsupported strategy") var errStrategy = errors.New("unsupported strategy")
@ -236,6 +238,8 @@ func (lb *LoadBalance) MarshalJSON() ([]byte, error) {
"all": all, "all": all,
"testUrl": lb.testUrl, "testUrl": lb.testUrl,
"expectedStatus": lb.expectedStatus, "expectedStatus": lb.expectedStatus,
"hidden": lb.Hidden,
"icon": lb.Icon,
}) })
} }
@ -268,5 +272,7 @@ func NewLoadBalance(option *GroupCommonOption, providers []provider.ProxyProvide
disableUDP: option.DisableUDP, disableUDP: option.DisableUDP,
testUrl: option.URL, testUrl: option.URL,
expectedStatus: option.ExpectedStatus, expectedStatus: option.ExpectedStatus,
Hidden: option.Hidden,
Icon: option.Icon,
}, nil }, nil
} }

View File

@ -37,6 +37,8 @@ type GroupCommonOption struct {
IncludeAll bool `group:"include-all,omitempty"` IncludeAll bool `group:"include-all,omitempty"`
IncludeAllProxies bool `group:"include-all-proxies,omitempty"` IncludeAllProxies bool `group:"include-all-proxies,omitempty"`
IncludeAllProviders bool `group:"include-all-providers,omitempty"` IncludeAllProviders bool `group:"include-all-providers,omitempty"`
Hidden bool `group:"hidden,omitempty"`
Icon string `group:"icon,omitempty"`
} }
func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, providersMap map[string]types.ProxyProvider, AllProxies []string, AllProviders []string) (C.ProxyAdapter, error) { func ParseProxyGroup(config map[string]any, proxyMap map[string]C.Proxy, providersMap map[string]types.ProxyProvider, AllProxies []string, AllProviders []string) (C.ProxyAdapter, error) {

View File

@ -3,6 +3,7 @@ package outboundgroup
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"github.com/metacubex/mihomo/adapter/outbound" "github.com/metacubex/mihomo/adapter/outbound"
"github.com/metacubex/mihomo/component/dialer" "github.com/metacubex/mihomo/component/dialer"
"github.com/metacubex/mihomo/component/proxydialer" "github.com/metacubex/mihomo/component/proxydialer"
@ -12,6 +13,8 @@ import (
type Relay struct { type Relay struct {
*GroupBase *GroupBase
Hidden bool
Icon string
} }
// DialContext implements C.ProxyAdapter // DialContext implements C.ProxyAdapter
@ -106,8 +109,10 @@ func (r *Relay) MarshalJSON() ([]byte, error) {
all = append(all, proxy.Name()) all = append(all, proxy.Name())
} }
return json.Marshal(map[string]any{ return json.Marshal(map[string]any{
"type": r.Type().String(), "type": r.Type().String(),
"all": all, "all": all,
"hidden": r.Hidden,
"icon": r.Icon,
}) })
} }
@ -157,5 +162,7 @@ func NewRelay(option *GroupCommonOption, providers []provider.ProxyProvider) *Re
"", "",
providers, providers,
}), }),
Hidden: option.Hidden,
Icon: option.Icon,
} }
} }

View File

@ -15,6 +15,8 @@ type Selector struct {
*GroupBase *GroupBase
disableUDP bool disableUDP bool
selected string selected string
Hidden bool
Icon string
} }
// DialContext implements C.ProxyAdapter // DialContext implements C.ProxyAdapter
@ -57,9 +59,11 @@ func (s *Selector) MarshalJSON() ([]byte, error) {
} }
return json.Marshal(map[string]any{ return json.Marshal(map[string]any{
"type": s.Type().String(), "type": s.Type().String(),
"now": s.Now(), "now": s.Now(),
"all": all, "all": all,
"hidden": s.Hidden,
"icon": s.Icon,
}) })
} }
@ -114,5 +118,7 @@ func NewSelector(option *GroupCommonOption, providers []provider.ProxyProvider)
}), }),
selected: "COMPATIBLE", selected: "COMPATIBLE",
disableUDP: option.DisableUDP, disableUDP: option.DisableUDP,
Hidden: option.Hidden,
Icon: option.Icon,
} }
} }

View File

@ -33,6 +33,8 @@ type URLTest struct {
expectedStatus string expectedStatus string
tolerance uint16 tolerance uint16
disableUDP bool disableUDP bool
Hidden bool
Icon string
fastNode C.Proxy fastNode C.Proxy
fastSingle *singledo.Single[C.Proxy] fastSingle *singledo.Single[C.Proxy]
} }
@ -174,6 +176,8 @@ func (u *URLTest) MarshalJSON() ([]byte, error) {
"testUrl": u.testUrl, "testUrl": u.testUrl,
"expectedStatus": u.expectedStatus, "expectedStatus": u.expectedStatus,
"fixed": u.selected, "fixed": u.selected,
"hidden": u.Hidden,
"icon": u.Icon,
}) })
} }
@ -237,6 +241,8 @@ func NewURLTest(option *GroupCommonOption, providers []provider.ProxyProvider, o
disableUDP: option.DisableUDP, disableUDP: option.DisableUDP,
testUrl: option.URL, testUrl: option.URL,
expectedStatus: option.ExpectedStatus, expectedStatus: option.ExpectedStatus,
Hidden: option.Hidden,
Icon: option.Icon,
} }
for _, option := range options { for _, option := range options {