From 755150a5131e5d38ed271bbf2a3bb57b0e5de94c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 22 Oct 2026 18:35:46 +0800 Subject: [PATCH] Fix config format output --- docs/schema.json | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- option/hysteria2.go | 3 --- option/openvpn.go | 2 +- option/outbound.go | 2 +- option/rule_action.go | 6 ------ option/shadowsocks.go | 6 +++--- option/tailscale.go | 13 +++---------- option/trojan.go | 2 +- option/usbip.go | 4 ++-- option/vless.go | 2 +- option/vmess.go | 4 ++-- 13 files changed, 19 insertions(+), 35 deletions(-) diff --git a/docs/schema.json b/docs/schema.json index 0b674f31..96a58c55 100644 --- a/docs/schema.json +++ b/docs/schema.json @@ -17004,10 +17004,10 @@ "User": { "type": "object", "properties": { - "Username": { + "username": { "type": "string" }, - "Password": { + "password": { "type": "string" } }, diff --git a/go.mod b/go.mod index 24d77711..23b77e7e 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/sagernet/netlink v0.0.0-20260814022025-64455d367bbf github.com/sagernet/nftables v0.3.0-mod.4 github.com/sagernet/quic-go v0.61.0-sing-box-mod.12 - github.com/sagernet/sing v0.9.7-0.20261023115459-9faf3c29ae9c + github.com/sagernet/sing v0.9.7-0.20261023115459-0678b21952a5 github.com/sagernet/sing-cloudflared v0.1.4-0.20261021152903-2d40d788fcf6 github.com/sagernet/sing-mux v0.3.10-0.20260929204512-caf09fe32475 github.com/sagernet/sing-openconnect v0.1.1-0.20260929151225-cbd68c45de58 diff --git a/go.sum b/go.sum index 739e776f..7efca8c7 100644 --- a/go.sum +++ b/go.sum @@ -318,8 +318,8 @@ github.com/sagernet/nftables v0.3.0-mod.4 h1:vnOtcDYeSXv2e5RoRuGH0lrpttQFJ8iC4IC github.com/sagernet/nftables v0.3.0-mod.4/go.mod h1:8kslHG4VvYNihcco+i6uxIX7qbT8A56T0y5q7U44ZaQ= github.com/sagernet/quic-go v0.61.0-sing-box-mod.12 h1:9/USaaiONHFeqBePb+4C/A0MBM2dmxED49UGBpHLHS4= github.com/sagernet/quic-go v0.61.0-sing-box-mod.12/go.mod h1:hmLC8GJPp+BrpBgrgJnacvI4fZGIhasuy1ROJJ8GR4E= -github.com/sagernet/sing v0.9.7-0.20261023115459-9faf3c29ae9c h1:wMpRBuv/lzJw/uVFucTMF7VWmHfV+m32fHILPWkzPoo= -github.com/sagernet/sing v0.9.7-0.20261023115459-9faf3c29ae9c/go.mod h1:K3Owt3xPhHugvlnlPPxZJ/exXdaJfEPOTNorGk4AXjo= +github.com/sagernet/sing v0.9.7-0.20261023115459-0678b21952a5 h1:CWi0GHLvGQlSAGPoSLJYhiTNN/2tjAdTBHHozl4p3gw= +github.com/sagernet/sing v0.9.7-0.20261023115459-0678b21952a5/go.mod h1:K3Owt3xPhHugvlnlPPxZJ/exXdaJfEPOTNorGk4AXjo= github.com/sagernet/sing-cloudflared v0.1.4-0.20261021152903-2d40d788fcf6 h1:cedQ/AnIVZXNS0RbV5E6xXbLan7Qu8rOj7+B1kvb7fs= github.com/sagernet/sing-cloudflared v0.1.4-0.20261021152903-2d40d788fcf6/go.mod h1:XEqEDYRCAYLaoPjZ1ifVWJg5iWAJHL2gOAXe/PM28Cg= github.com/sagernet/sing-mux v0.3.10-0.20260929204512-caf09fe32475 h1:aG0DqHEOjax7DyfE1GTAXZotOg3QGVCz3/8rCSua2kg= diff --git a/option/hysteria2.go b/option/hysteria2.go index 237109b2..f4df2d9f 100644 --- a/option/hysteria2.go +++ b/option/hysteria2.go @@ -78,9 +78,6 @@ func (o Hysteria2Obfs) MarshalJSON() ([]byte, error) { default: return nil, E.New("unknown obfs type: ", o.Type) } - if v == nil { - return json.Marshal(_Hysteria2Obfs(o)) - } return badjson.MarshallObjects(_Hysteria2Obfs(o), v) } diff --git a/option/openvpn.go b/option/openvpn.go index d62aaf98..f006f091 100644 --- a/option/openvpn.go +++ b/option/openvpn.go @@ -195,7 +195,7 @@ type OpenVPNPushOptions struct { } type OpenVPNPushDNSServerOptions struct { - Priority int `json:"priority"` + Priority int `json:"priority,omitempty"` Addresses badoption.Listable[string] `json:"addresses"` ResolveDomains badoption.Listable[string] `json:"resolve_domains,omitempty"` DNSSEC string `json:"dnssec,omitempty" enum:"yes,optional,no"` diff --git a/option/outbound.go b/option/outbound.go index 4590b48d..5780929a 100644 --- a/option/outbound.go +++ b/option/outbound.go @@ -182,7 +182,7 @@ type ServerOptionsWrapper interface { type ServerOptions struct { Server string `json:"server"` - ServerPort uint16 `json:"server_port"` + ServerPort uint16 `json:"server_port,omitempty"` } func (o ServerOptions) Build() M.Socksaddr { diff --git a/option/rule_action.go b/option/rule_action.go index e9bf1e16..33ddd2bd 100644 --- a/option/rule_action.go +++ b/option/rule_action.go @@ -48,9 +48,6 @@ func (r RuleAction) MarshalJSON() ([]byte, error) { default: return nil, E.New("unknown rule action: " + r.Action) } - if v == nil { - return badjson.MarshallObjects(_RuleAction(r)) - } return badjson.MarshallObjects(_RuleAction(r), v) } @@ -124,9 +121,6 @@ func (r DNSRuleAction) MarshalJSON() ([]byte, error) { default: return nil, E.New("unknown DNS rule action: " + r.Action) } - if v == nil { - return badjson.MarshallObjects(_DNSRuleAction(r)) - } return badjson.MarshallObjects(_DNSRuleAction(r), v) } diff --git a/option/shadowsocks.go b/option/shadowsocks.go index 484aafec..2fbaebf9 100644 --- a/option/shadowsocks.go +++ b/option/shadowsocks.go @@ -12,12 +12,12 @@ type ShadowsocksInboundOptions struct { } type ShadowsocksUser struct { - Name string `json:"name"` + Name string `json:"name,omitempty"` Password string `json:"password"` } type ShadowsocksDestination struct { - Name string `json:"name"` + Name string `json:"name,omitempty"` Password string `json:"password"` ServerOptions } @@ -26,7 +26,7 @@ type ShadowsocksOutboundOptions struct { DialerOptions ServerOptions Method string `json:"method" enum:"none,aes-128-gcm,aes-192-gcm,aes-256-gcm,chacha20-ietf-poly1305,xchacha20-ietf-poly1305,2022-blake3-aes-128-gcm,2022-blake3-aes-256-gcm,2022-blake3-chacha20-poly1305,aes-128-ctr,aes-192-ctr,aes-256-ctr,aes-128-cfb,aes-192-cfb,aes-256-cfb,rc4-md5,chacha20-ietf,xchacha20"` - Password string `json:"password"` + Password string `json:"password,omitempty"` Plugin string `json:"plugin,omitempty"` PluginOptions string `json:"plugin_opts,omitempty"` Network NetworkList `json:"network,omitempty"` diff --git a/option/tailscale.go b/option/tailscale.go index 1142b2e0..1e440f7c 100644 --- a/option/tailscale.go +++ b/option/tailscale.go @@ -164,17 +164,10 @@ type _DERPSTUNListenOptions struct { type DERPSTUNListenOptions _DERPSTUNListenOptions func (d DERPSTUNListenOptions) MarshalJSON() ([]byte, error) { - portOptions := _DERPSTUNListenOptions{ - Enabled: d.Enabled, - ListenOptions: ListenOptions{ - ListenPort: d.ListenPort, - }, - } - if _DERPSTUNListenOptions(d) == portOptions { - return json.Marshal(d.Enabled) - } else { - return json.Marshal(_DERPSTUNListenOptions(d)) + if d.Enabled && d.ListenPort != 0 && d.ListenOptions == (ListenOptions{ListenPort: d.ListenPort}) { + return json.Marshal(d.ListenPort) } + return json.Marshal(_DERPSTUNListenOptions(d)) } func (d *DERPSTUNListenOptions) UnmarshalJSON(bytes []byte) error { diff --git a/option/trojan.go b/option/trojan.go index 7d36c8d2..5d230b22 100644 --- a/option/trojan.go +++ b/option/trojan.go @@ -11,7 +11,7 @@ type TrojanInboundOptions struct { } type TrojanUser struct { - Name string `json:"name"` + Name string `json:"name,omitempty"` Password string `json:"password"` } diff --git a/option/usbip.go b/option/usbip.go index 18741d3a..066c361c 100644 --- a/option/usbip.go +++ b/option/usbip.go @@ -23,8 +23,8 @@ type _USBIPServerServiceOptions struct { type USBIPServerServiceOptions _USBIPServerServiceOptions func (o USBIPServerServiceOptions) MarshalJSON() ([]byte, error) { - if o.Options == nil { - return json.Marshal(_USBIPServerServiceOptions(o)) + if o.Provider == USBIPProviderDefault { + o.Provider = "" } return badjson.MarshallObjects(_USBIPServerServiceOptions(o), o.Options) } diff --git a/option/vless.go b/option/vless.go index 5acf2aee..1f13537d 100644 --- a/option/vless.go +++ b/option/vless.go @@ -9,7 +9,7 @@ type VLESSInboundOptions struct { } type VLESSUser struct { - Name string `json:"name"` + Name string `json:"name,omitempty"` UUID string `json:"uuid"` Flow string `json:"flow,omitempty"` } diff --git a/option/vmess.go b/option/vmess.go index f4dd2828..fbb6645b 100644 --- a/option/vmess.go +++ b/option/vmess.go @@ -9,7 +9,7 @@ type VMessInboundOptions struct { } type VMessUser struct { - Name string `json:"name"` + Name string `json:"name,omitempty"` UUID string `json:"uuid"` AlterId int `json:"alterId,omitempty"` } @@ -18,7 +18,7 @@ type VMessOutboundOptions struct { DialerOptions ServerOptions UUID string `json:"uuid"` - Security string `json:"security" enum:"auto,none,zero,aes-128-cfb,aes-128-gcm,chacha20-poly1305"` + Security string `json:"security,omitempty" enum:"auto,none,zero,aes-128-cfb,aes-128-gcm,chacha20-poly1305"` AlterId int `json:"alter_id,omitempty"` GlobalPadding bool `json:"global_padding,omitempty"` AuthenticatedLength bool `json:"authenticated_length,omitempty"`