1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-24 11:24:41 -05:00
This commit is contained in:
Nite07 2024-03-11 19:28:22 +08:00
parent 7c8cb5d7f6
commit f1d1029c95
4 changed files with 295 additions and 246 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.vscode .vscode
dist dist
*test.go *test.go
template.json

View File

@ -24,12 +24,25 @@ var convertCmd = &cobra.Command{
proxies, _ := cmd.Flags().GetStringSlice("proxy") proxies, _ := cmd.Flags().GetStringSlice("proxy")
template, _ := cmd.Flags().GetString("template") template, _ := cmd.Flags().GetString("template")
if template == "" { if template == "" {
result, err := ConvertSubscriptionsToJson(subscriptions) proxyList, err := ConvertSubscriptionsToSProxy(subscriptions)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
fmt.Println(result) for _, p := range proxies {
result, err := ConvertCProxyToSProxy(p)
if err != nil {
fmt.Println(err)
return
}
proxyList = append(proxyList, result)
}
result, err := json.Marshal(proxyList)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(result))
} else { } else {
config, err := ConvertWithTemplate(subscriptions, proxies, template) config, err := ConvertWithTemplate(subscriptions, proxies, template)
if err != nil { if err != nil {
@ -73,6 +86,7 @@ func Convert(urls []string, proxies []string) ([]model.Proxy, error) {
func ConvertWithTemplate(urls []string, proxies []string, template string) (model.Config, error) { func ConvertWithTemplate(urls []string, proxies []string, template string) (model.Config, error) {
proxyList := make([]model.Proxy, 0) proxyList := make([]model.Proxy, 0)
newProxies, err := ConvertSubscriptionsToSProxy(urls) newProxies, err := ConvertSubscriptionsToSProxy(urls)
newOutboundTagList := make([]string, 0)
if err != nil { if err != nil {
return model.Config{}, err return model.Config{}, err
} }
@ -97,7 +111,23 @@ func ConvertWithTemplate(urls []string, proxies []string, template string) (mode
if err != nil { if err != nil {
return model.Config{}, err return model.Config{}, err
} }
for _, outbound := range newOutbounds {
newOutboundTagList = append(newOutboundTagList, outbound.Tag)
}
config.Outbounds = append(config.Outbounds, newOutbounds...) config.Outbounds = append(config.Outbounds, newOutbounds...)
for i, outbound := range config.Outbounds {
if outbound.Type == "urltest" || outbound.Type == "selector" {
var parsedOutbound []string = make([]string, 0)
for _, o := range outbound.Outbounds {
if o == "<all-proxy-tags>" {
parsedOutbound = append(parsedOutbound, newOutboundTagList...)
} else {
parsedOutbound = append(parsedOutbound, o)
}
}
config.Outbounds[i].Outbounds = parsedOutbound
}
}
return config, nil return config, nil
} }

View File

@ -1,11 +1,58 @@
package model package model
import "encoding/json"
type Listable[T any] []T
func (l *Listable[T]) UnmarshalJSON(data []byte) error {
var arr []T
if err := json.Unmarshal(data, &arr); err == nil {
*l = arr
return nil
}
var v T
if err := json.Unmarshal(data, &v); err == nil {
*l = []T{v}
return nil
}
return nil
}
type Obfs struct {
Str string
Obfs *Hysteria2Obfs
IsStr bool
}
func (o *Obfs) UnmarshalJSON(data []byte) error {
var str string
if err := json.Unmarshal(data, &str); err == nil {
o.Str = str
o.IsStr = true
return nil
}
var obfs Hysteria2Obfs
if err := json.Unmarshal(data, &obfs); err == nil {
o.IsStr = false
o.Obfs = &obfs
return nil
}
return nil
}
func (o Obfs) MarshalJSON() ([]byte, error) {
if o.IsStr {
return json.Marshal(o.Str)
}
return json.Marshal(o.Obfs)
}
type Config struct { type Config struct {
Log *LogOptions `json:"log,omitempty"` Log *LogOptions `json:"log,omitempty"`
DNS *DNSOptions `json:"dns,omitempty"` DNS *DNSOptions `json:"dns,omitempty"`
NTP *NTPOptions `json:"ntp,omitempty"` NTP *NTPOptions `json:"ntp,omitempty"`
Inbounds []Inbound `json:"inbounds,omitempty"` Inbounds Listable[Inbound] `json:"inbounds,omitempty"`
Outbounds []Outbound `json:"outbounds,omitempty"` Outbounds Listable[Outbound] `json:"outbounds,omitempty"`
Route *RouteOptions `json:"route,omitempty"` Route *RouteOptions `json:"route,omitempty"`
Experimental *ExperimentalOptions `json:"experimental,omitempty"` Experimental *ExperimentalOptions `json:"experimental,omitempty"`
} }
@ -18,8 +65,8 @@ type LogOptions struct {
} }
type DNSOptions struct { type DNSOptions struct {
Servers []DNSServerOptions `json:"servers,omitempty"` Servers Listable[DNSServerOptions] `json:"servers,omitempty"`
Rules []DNSRule `json:"rules,omitempty"` Rules Listable[DNSRule] `json:"rules,omitempty"`
Final string `json:"final,omitempty"` Final string `json:"final,omitempty"`
ReverseMapping bool `json:"reverse_mapping,omitempty"` ReverseMapping bool `json:"reverse_mapping,omitempty"`
FakeIP *DNSFakeIPOptions `json:"fakeip,omitempty"` FakeIP *DNSFakeIPOptions `json:"fakeip,omitempty"`
@ -42,45 +89,45 @@ type DNSServerOptions struct {
type DNSRule struct { type DNSRule struct {
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
Inbound []string `json:"inbound,omitempty"` Inbound Listable[string] `json:"inbound,omitempty"`
IPVersion int `json:"ip_version,omitempty"` IPVersion int `json:"ip_version,omitempty"`
QueryType []string `json:"query_type,omitempty"` QueryType Listable[uint16] `json:"query_type,omitempty"`
Network []string `json:"network,omitempty"` Network Listable[string] `json:"network,omitempty"`
AuthUser []string `json:"auth_user,omitempty"` AuthUser Listable[string] `json:"auth_user,omitempty"`
Protocol []string `json:"protocol,omitempty"` Protocol Listable[string] `json:"protocol,omitempty"`
Domain []string `json:"domain,omitempty"` Domain Listable[string] `json:"domain,omitempty"`
DomainSuffix []string `json:"domain_suffix,omitempty"` DomainSuffix Listable[string] `json:"domain_suffix,omitempty"`
DomainKeyword []string `json:"domain_keyword,omitempty"` DomainKeyword Listable[string] `json:"domain_keyword,omitempty"`
DomainRegex []string `json:"domain_regex,omitempty"` DomainRegex Listable[string] `json:"domain_regex,omitempty"`
Geosite []string `json:"geosite,omitempty"` Geosite Listable[string] `json:"geosite,omitempty"`
SourceGeoIP []string `json:"source_geoip,omitempty"` SourceGeoIP Listable[string] `json:"source_geoip,omitempty"`
GeoIP []string `json:"geoip,omitempty"` GeoIP Listable[string] `json:"geoip,omitempty"`
IPCIDR []string `json:"ip_cidr,omitempty"` IPCIDR Listable[string] `json:"ip_cidr,omitempty"`
IPIsPrivate bool `json:"ip_is_private,omitempty"` IPIsPrivate bool `json:"ip_is_private,omitempty"`
SourceIPCIDR []string `json:"source_ip_cidr,omitempty"` SourceIPCIDR Listable[string] `json:"source_ip_cidr,omitempty"`
SourceIPIsPrivate bool `json:"source_ip_is_private,omitempty"` SourceIPIsPrivate bool `json:"source_ip_is_private,omitempty"`
SourcePort []uint16 `json:"source_port,omitempty"` SourcePort Listable[uint16] `json:"source_port,omitempty"`
SourcePortRange []string `json:"source_port_range,omitempty"` SourcePortRange Listable[string] `json:"source_port_range,omitempty"`
Port []uint16 `json:"port,omitempty"` Port Listable[uint16] `json:"port,omitempty"`
PortRange []string `json:"port_range,omitempty"` PortRange Listable[string] `json:"port_range,omitempty"`
ProcessName []string `json:"process_name,omitempty"` ProcessName Listable[string] `json:"process_name,omitempty"`
ProcessPath []string `json:"process_path,omitempty"` ProcessPath Listable[string] `json:"process_path,omitempty"`
PackageName []string `json:"package_name,omitempty"` PackageName Listable[string] `json:"package_name,omitempty"`
User []string `json:"user,omitempty"` User Listable[string] `json:"user,omitempty"`
UserID []int32 `json:"user_id,omitempty"` UserID Listable[int32] `json:"user_id,omitempty"`
Outbound []string `json:"outbound,omitempty"` Outbound Listable[string] `json:"outbound,omitempty"`
ClashMode string `json:"clash_mode,omitempty"` ClashMode string `json:"clash_mode,omitempty"`
WIFISSID []string `json:"wifi_ssid,omitempty"` WIFISSID Listable[string] `json:"wifi_ssid,omitempty"`
WIFIBSSID []string `json:"wifi_bssid,omitempty"` WIFIBSSID Listable[string] `json:"wifi_bssid,omitempty"`
RuleSet []string `json:"rule_set,omitempty"` RuleSet Listable[string] `json:"rule_set,omitempty"`
RuleSetIPCIDRMatchSource bool `json:"rule_set_ipcidr_match_source,omitempty"` RuleSetIPCIDRMatchSource bool `json:"rule_set_ipcidr_match_source,omitempty"`
Invert bool `json:"invert,omitempty"` Invert bool `json:"invert,omitempty"`
Server string `json:"server,omitempty"` Server string `json:"server,omitempty"`
DisableCache bool `json:"disable_cache,omitempty"` DisableCache bool `json:"disable_cache,omitempty"`
RewriteTTL *uint32 `json:"rewrite_ttl,omitempty"` RewriteTTL uint32 `json:"rewrite_ttl,omitempty"`
ClientSubnet string `json:"client_subnet,omitempty"` ClientSubnet string `json:"client_subnet,omitempty"`
Mode string `json:"mode"` Mode string `json:"mode"`
Rules []DNSRule `json:"rules,omitempty"` Rules Listable[DNSRule] `json:"rules,omitempty"`
} }
type DNSFakeIPOptions struct { type DNSFakeIPOptions struct {
@ -116,23 +163,23 @@ type Inbound struct {
InterfaceName string `json:"interface_name,omitempty"` InterfaceName string `json:"interface_name,omitempty"`
MTU uint32 `json:"mtu,omitempty"` MTU uint32 `json:"mtu,omitempty"`
GSO bool `json:"gso,omitempty"` GSO bool `json:"gso,omitempty"`
Inet4Address []string `json:"inet4_address,omitempty"` Inet4Address Listable[string] `json:"inet4_address,omitempty"`
Inet6Address []string `json:"inet6_address,omitempty"` Inet6Address Listable[string] `json:"inet6_address,omitempty"`
AutoRoute bool `json:"auto_route,omitempty"` AutoRoute bool `json:"auto_route,omitempty"`
StrictRoute bool `json:"strict_route,omitempty"` StrictRoute bool `json:"strict_route,omitempty"`
Inet4RouteAddress []string `json:"inet4_route_address,omitempty"` Inet4RouteAddress Listable[string] `json:"inet4_route_address,omitempty"`
Inet6RouteAddress []string `json:"inet6_route_address,omitempty"` Inet6RouteAddress Listable[string] `json:"inet6_route_address,omitempty"`
Inet4RouteExcludeAddress []string `json:"inet4_route_exclude_address,omitempty"` Inet4RouteExcludeAddress Listable[string] `json:"inet4_route_exclude_address,omitempty"`
Inet6RouteExcludeAddress []string `json:"inet6_route_exclude_address,omitempty"` Inet6RouteExcludeAddress Listable[string] `json:"inet6_route_exclude_address,omitempty"`
IncludeInterface []string `json:"include_interface,omitempty"` IncludeInterface Listable[string] `json:"include_interface,omitempty"`
ExcludeInterface []string `json:"exclude_interface,omitempty"` ExcludeInterface Listable[string] `json:"exclude_interface,omitempty"`
IncludeUID []uint32 `json:"include_uid,omitempty"` IncludeUID Listable[uint32] `json:"include_uid,omitempty"`
IncludeUIDRange []string `json:"include_uid_range,omitempty"` IncludeUIDRange Listable[string] `json:"include_uid_range,omitempty"`
ExcludeUID []uint32 `json:"exclude_uid,omitempty"` ExcludeUID Listable[uint32] `json:"exclude_uid,omitempty"`
ExcludeUIDRange []string `json:"exclude_uid_range,omitempty"` ExcludeUIDRange Listable[string] `json:"exclude_uid_range,omitempty"`
IncludeAndroidUser []int `json:"include_android_user,omitempty"` IncludeAndroidUser Listable[int] `json:"include_android_user,omitempty"`
IncludePackage []string `json:"include_package,omitempty"` IncludePackage Listable[string] `json:"include_package,omitempty"`
ExcludePackage []string `json:"exclude_package,omitempty"` ExcludePackage Listable[string] `json:"exclude_package,omitempty"`
EndpointIndependentNat bool `json:"endpoint_independent_nat,omitempty"` EndpointIndependentNat bool `json:"endpoint_independent_nat,omitempty"`
UDPTimeout string `json:"udp_timeout,omitempty"` UDPTimeout string `json:"udp_timeout,omitempty"`
Stack string `json:"stack,omitempty"` Stack string `json:"stack,omitempty"`
@ -152,8 +199,8 @@ type HTTPProxyOptions struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
Server string `json:"server"` Server string `json:"server"`
ServerPort uint16 `json:"server_port"` ServerPort uint16 `json:"server_port"`
BypassDomain []string `json:"bypass_domain,omitempty"` BypassDomain Listable[string] `json:"bypass_domain,omitempty"`
MatchDomain []string `json:"match_domain,omitempty"` MatchDomain Listable[string] `json:"match_domain,omitempty"`
} }
type Outbound struct { type Outbound struct {
@ -175,8 +222,8 @@ type Outbound struct {
OverrideAddress string `json:"override_address,omitempty"` OverrideAddress string `json:"override_address,omitempty"`
OverridePort uint16 `json:"override_port,omitempty"` OverridePort uint16 `json:"override_port,omitempty"`
ProxyProtocol uint8 `json:"proxy_protocol,omitempty"` ProxyProtocol uint8 `json:"proxy_protocol,omitempty"`
Server string `json:"server"` Server string `json:"server,omitempty"`
ServerPort uint16 `json:"server_port"` ServerPort uint16 `json:"server_port,omitempty"`
Version string `json:"version,omitempty"` Version string `json:"version,omitempty"`
Username string `json:"username,omitempty"` Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"` Password string `json:"password,omitempty"`
@ -184,13 +231,13 @@ type Outbound struct {
UDPOverTCP *UDPOverTCPOptions `json:"udp_over_tcp,omitempty"` UDPOverTCP *UDPOverTCPOptions `json:"udp_over_tcp,omitempty"`
TLS *OutboundTLSOptions `json:"tls,omitempty"` TLS *OutboundTLSOptions `json:"tls,omitempty"`
Path string `json:"path,omitempty"` Path string `json:"path,omitempty"`
Headers map[string][]string `json:"headers,omitempty"` Headers map[string]Listable[string] `json:"headers,omitempty"`
Method string `json:"method"` Method string `json:"method,omitempty"`
Plugin string `json:"plugin,omitempty"` Plugin string `json:"plugin,omitempty"`
PluginOptions string `json:"plugin_opts,omitempty"` PluginOptions string `json:"plugin_opts,omitempty"`
Multiplex *OutboundMultiplexOptions `json:"multiplex,omitempty"` Multiplex *OutboundMultiplexOptions `json:"multiplex,omitempty"`
UUID string `json:"uuid"` UUID string `json:"uuid,omitempty"`
Security string `json:"security"` Security string `json:"security,omitempty"`
AlterId int `json:"alter_id,omitempty"` AlterId int `json:"alter_id,omitempty"`
GlobalPadding bool `json:"global_padding,omitempty"` GlobalPadding bool `json:"global_padding,omitempty"`
AuthenticatedLength bool `json:"authenticated_length,omitempty"` AuthenticatedLength bool `json:"authenticated_length,omitempty"`
@ -199,36 +246,33 @@ type Outbound struct {
SystemInterface bool `json:"system_interface,omitempty"` SystemInterface bool `json:"system_interface,omitempty"`
GSO bool `json:"gso,omitempty"` GSO bool `json:"gso,omitempty"`
InterfaceName string `json:"interface_name,omitempty"` InterfaceName string `json:"interface_name,omitempty"`
LocalAddress []string `json:"local_address"` LocalAddress Listable[string] `json:"local_address,omitempty"`
PrivateKey string `json:"private_key"` PrivateKey string `json:"private_key,omitempty"`
Peers []WireGuardPeer `json:"peers,omitempty"` Peers Listable[WireGuardPeer] `json:"peers,omitempty"`
PeerPublicKey string `json:"peer_public_key"` PeerPublicKey string `json:"peer_public_key,omitempty"`
PreSharedKey string `json:"pre_shared_key,omitempty"` PreSharedKey string `json:"pre_shared_key,omitempty"`
Reserved []uint8 `json:"reserved,omitempty"` Reserved Listable[uint8] `json:"reserved,omitempty"`
Workers int `json:"workers,omitempty"` Workers int `json:"workers,omitempty"`
MTU uint32 `json:"mtu,omitempty"` MTU uint32 `json:"mtu,omitempty"`
Up string `json:"up,omitempty"` Up string `json:"up,omitempty"`
UpMbps int `json:"up_mbps,omitempty"` UpMbps int `json:"up_mbps,omitempty"`
Down string `json:"down,omitempty"` Down string `json:"down,omitempty"`
DownMbps int `json:"down_mbps,omitempty"` DownMbps int `json:"down_mbps,omitempty"`
Obfs struct { Obfs *Obfs `json:"obfs,omitempty"`
string Auth Listable[byte] `json:"auth,omitempty"`
*Hysteria2Obfs
} `json:"obfs,omitempty"`
Auth []byte `json:"auth,omitempty"`
AuthString string `json:"auth_str,omitempty"` AuthString string `json:"auth_str,omitempty"`
ReceiveWindowConn uint64 `json:"recv_window_conn,omitempty"` ReceiveWindowConn uint64 `json:"recv_window_conn,omitempty"`
ReceiveWindow uint64 `json:"recv_window,omitempty"` ReceiveWindow uint64 `json:"recv_window,omitempty"`
DisableMTUDiscovery bool `json:"disable_mtu_discovery,omitempty"` DisableMTUDiscovery bool `json:"disable_mtu_discovery,omitempty"`
ExecutablePath string `json:"executable_path,omitempty"` ExecutablePath string `json:"executable_path,omitempty"`
ExtraArgs []string `json:"extra_args,omitempty"` ExtraArgs Listable[string] `json:"extra_args,omitempty"`
DataDirectory string `json:"data_directory,omitempty"` DataDirectory string `json:"data_directory,omitempty"`
Options map[string]string `json:"torrc,omitempty"` Options map[string]string `json:"torrc,omitempty"`
User string `json:"user,omitempty"` User string `json:"user,omitempty"`
PrivateKeyPath string `json:"private_key_path,omitempty"` PrivateKeyPath string `json:"private_key_path,omitempty"`
PrivateKeyPassphrase string `json:"private_key_passphrase,omitempty"` PrivateKeyPassphrase string `json:"private_key_passphrase,omitempty"`
HostKey []string `json:"host_key,omitempty"` HostKey Listable[string] `json:"host_key,omitempty"`
HostKeyAlgorithms []string `json:"host_key_algorithms,omitempty"` HostKeyAlgorithms Listable[string] `json:"host_key_algorithms,omitempty"`
ClientVersion string `json:"client_version,omitempty"` ClientVersion string `json:"client_version,omitempty"`
ObfsParam string `json:"obfs_param,omitempty"` ObfsParam string `json:"obfs_param,omitempty"`
Protocol string `json:"protocol,omitempty"` Protocol string `json:"protocol,omitempty"`
@ -241,7 +285,7 @@ type Outbound struct {
Heartbeat string `json:"heartbeat,omitempty"` Heartbeat string `json:"heartbeat,omitempty"`
BrutalDebug bool `json:"brutal_debug,omitempty"` BrutalDebug bool `json:"brutal_debug,omitempty"`
Default string `json:"default,omitempty"` Default string `json:"default,omitempty"`
Outbounds []string `json:"outbounds"` Outbounds Listable[string] `json:"outbounds,omitempty"`
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
Interval string `json:"interval,omitempty"` Interval string `json:"interval,omitempty"`
Tolerance uint16 `json:"tolerance,omitempty"` Tolerance uint16 `json:"tolerance,omitempty"`
@ -254,15 +298,15 @@ type WireGuardPeer struct {
ServerPort uint16 `json:"server_port"` ServerPort uint16 `json:"server_port"`
PublicKey string `json:"public_key,omitempty"` PublicKey string `json:"public_key,omitempty"`
PreSharedKey string `json:"pre_shared_key,omitempty"` PreSharedKey string `json:"pre_shared_key,omitempty"`
AllowedIPs []string `json:"allowed_ips,omitempty"` AllowedIPs Listable[string] `json:"allowed_ips,omitempty"`
Reserved []uint8 `json:"reserved,omitempty"` Reserved Listable[uint8] `json:"reserved,omitempty"`
} }
type RouteOptions struct { type RouteOptions struct {
GeoIP *GeoIPOptions `json:"geoip,omitempty"` GeoIP *GeoIPOptions `json:"geoip,omitempty"`
Geosite *GeositeOptions `json:"geosite,omitempty"` Geosite *GeositeOptions `json:"geosite,omitempty"`
Rules []Rule `json:"rules,omitempty"` Rules Listable[Rule] `json:"rules,omitempty"`
RuleSet []RuleSet `json:"rule_set,omitempty"` RuleSet Listable[RuleSet] `json:"rule_set,omitempty"`
Final string `json:"final,omitempty"` Final string `json:"final,omitempty"`
FindProcess bool `json:"find_process,omitempty"` FindProcess bool `json:"find_process,omitempty"`
AutoDetectInterface bool `json:"auto_detect_interface,omitempty"` AutoDetectInterface bool `json:"auto_detect_interface,omitempty"`
@ -273,40 +317,40 @@ type RouteOptions struct {
type Rule struct { type Rule struct {
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
Inbound []string `json:"inbound,omitempty"` Inbound Listable[string] `json:"inbound,omitempty"`
IPVersion int `json:"ip_version,omitempty"` IPVersion int `json:"ip_version,omitempty"`
Network []string `json:"network,omitempty"` Network Listable[string] `json:"network,omitempty"`
AuthUser []string `json:"auth_user,omitempty"` AuthUser Listable[string] `json:"auth_user,omitempty"`
Protocol []string `json:"protocol,omitempty"` Protocol string `json:"protocol,omitempty"`
Domain []string `json:"domain,omitempty"` Domain Listable[string] `json:"domain,omitempty"`
DomainSuffix []string `json:"domain_suffix,omitempty"` DomainSuffix Listable[string] `json:"domain_suffix,omitempty"`
DomainKeyword []string `json:"domain_keyword,omitempty"` DomainKeyword Listable[string] `json:"domain_keyword,omitempty"`
DomainRegex []string `json:"domain_regex,omitempty"` DomainRegex Listable[string] `json:"domain_regex,omitempty"`
Geosite []string `json:"geosite,omitempty"` Geosite Listable[string] `json:"geosite,omitempty"`
SourceGeoIP []string `json:"source_geoip,omitempty"` SourceGeoIP Listable[string] `json:"source_geoip,omitempty"`
GeoIP []string `json:"geoip,omitempty"` GeoIP Listable[string] `json:"geoip,omitempty"`
SourceIPCIDR []string `json:"source_ip_cidr,omitempty"` SourceIPCIDR Listable[string] `json:"source_ip_cidr,omitempty"`
SourceIPIsPrivate bool `json:"source_ip_is_private,omitempty"` SourceIPIsPrivate bool `json:"source_ip_is_private,omitempty"`
IPCIDR []string `json:"ip_cidr,omitempty"` IPCIDR Listable[string] `json:"ip_cidr,omitempty"`
IPIsPrivate bool `json:"ip_is_private,omitempty"` IPIsPrivate bool `json:"ip_is_private,omitempty"`
SourcePort []uint16 `json:"source_port,omitempty"` SourcePort Listable[uint16] `json:"source_port,omitempty"`
SourcePortRange []string `json:"source_port_range,omitempty"` SourcePortRange Listable[string] `json:"source_port_range,omitempty"`
Port []uint16 `json:"port,omitempty"` Port Listable[uint16] `json:"port,omitempty"`
PortRange []string `json:"port_range,omitempty"` PortRange Listable[string] `json:"port_range,omitempty"`
ProcessName []string `json:"process_name,omitempty"` ProcessName Listable[string] `json:"process_name,omitempty"`
ProcessPath []string `json:"process_path,omitempty"` ProcessPath Listable[string] `json:"process_path,omitempty"`
PackageName []string `json:"package_name,omitempty"` PackageName Listable[string] `json:"package_name,omitempty"`
User []string `json:"user,omitempty"` User Listable[string] `json:"user,omitempty"`
UserID []int32 `json:"user_id,omitempty"` UserID Listable[int32] `json:"user_id,omitempty"`
ClashMode string `json:"clash_mode,omitempty"` ClashMode string `json:"clash_mode,omitempty"`
WIFISSID []string `json:"wifi_ssid,omitempty"` WIFISSID Listable[string] `json:"wifi_ssid,omitempty"`
WIFIBSSID []string `json:"wifi_bssid,omitempty"` WIFIBSSID Listable[string] `json:"wifi_bssid,omitempty"`
RuleSet []string `json:"rule_set,omitempty"` RuleSet Listable[string] `json:"rule_set,omitempty"`
RuleSetIPCIDRMatchSource bool `json:"rule_set_ipcidr_match_source,omitempty"` RuleSetIPCIDRMatchSource bool `json:"rule_set_ipcidr_match_source,omitempty"`
Invert bool `json:"invert,omitempty"` Invert bool `json:"invert,omitempty"`
Outbound string `json:"outbound,omitempty"` Outbound string `json:"outbound,omitempty"`
Mode string `json:"mode"` Mode string `json:"mode,omitempty"`
Rules []Rule `json:"rules,omitempty"` Rules Listable[Rule] `json:"rules,omitempty"`
} }
type GeoIPOptions struct { type GeoIPOptions struct {
@ -373,7 +417,7 @@ type V2RayAPIOptions struct {
type V2RayStatsServiceOptions struct { type V2RayStatsServiceOptions struct {
Enabled bool `json:"enabled,omitempty"` Enabled bool `json:"enabled,omitempty"`
Inbounds []string `json:"inbounds,omitempty"` Inbounds Listable[string] `json:"inbounds,omitempty"`
Outbounds []string `json:"outbounds,omitempty"` Outbounds Listable[string] `json:"outbounds,omitempty"`
Users []string `json:"users,omitempty"` Users Listable[string] `json:"users,omitempty"`
} }

View File

@ -18,29 +18,3 @@ type Hysteria2 struct {
TLS *OutboundTLSOptions `json:"tls,omitempty"` TLS *OutboundTLSOptions `json:"tls,omitempty"`
BrutalDebug bool `json:"brutal_debug,omitempty"` BrutalDebug bool `json:"brutal_debug,omitempty"`
} }
// func (h *Hysteria2OutboundOptions) MarshalJSON() ([]byte, error) {
// val := reflect.ValueOf(h)
// out := make(map[string]interface{})
// typ := val.Type()
// for i := 0; i < val.NumField(); i++ {
// field := val.Field(i)
// fieldType := typ.Field(i)
// if field.Kind() == reflect.Struct {
// for j := 0; j < field.NumField(); j++ {
// subField := field.Field(j)
// subFieldType := fieldType.Type.Field(j)
// jsonTag := subFieldType.Tag.Get("json")
// if jsonTag != "" && jsonTag != "-" {
// out[jsonTag] = subField.Interface()
// }
// }
// } else {
// jsonTag := fieldType.Tag.Get("json")
// if jsonTag != "" && jsonTag != "-" {
// out[jsonTag] = field.Interface()
// }
// }
// }
// return json.Marshal(out)
// }