Fix omitempty for JSON struct fields

Claude-Session: https://claude.ai/code/session_01NxBrtZjwwaJC8uxCNbgmKu
This commit is contained in:
世界
2026-09-08 15:03:09 +08:00
parent b2a5ac3f60
commit d6ec014ca4
5 changed files with 17 additions and 17 deletions
+5 -5
View File
@@ -12,11 +12,11 @@ import (
)
type HTTP2Options struct {
IdleTimeout badoption.Duration `json:"idle_timeout,omitempty"`
KeepAlivePeriod badoption.Duration `json:"keep_alive_period,omitempty"`
StreamReceiveWindow byteformats.MemoryBytes `json:"stream_receive_window,omitempty"`
ConnectionReceiveWindow byteformats.MemoryBytes `json:"connection_receive_window,omitempty"`
MaxConcurrentStreams int `json:"max_concurrent_streams,omitempty"`
IdleTimeout badoption.Duration `json:"idle_timeout,omitempty"`
KeepAlivePeriod badoption.Duration `json:"keep_alive_period,omitempty"`
StreamReceiveWindow *byteformats.MemoryBytes `json:"stream_receive_window,omitempty"`
ConnectionReceiveWindow *byteformats.MemoryBytes `json:"connection_receive_window,omitempty"`
MaxConcurrentStreams int `json:"max_concurrent_streams,omitempty"`
}
type QUICOptions struct {
+4 -4
View File
@@ -25,8 +25,8 @@ type OpenVPNClientEndpointOptions struct {
Servers []OpenVPNRemoteOptions `json:"servers,omitempty"`
RemoteRandom bool `json:"remote_random,omitempty"`
Address badoption.Listable[netip.Prefix] `json:"address,omitempty"`
PeerAddress badoption.Addr `json:"peer_address,omitempty"`
PeerAddressIPv6 badoption.Addr `json:"peer_address_ipv6,omitempty"`
PeerAddress *badoption.Addr `json:"peer_address,omitempty"`
PeerAddressIPv6 *badoption.Addr `json:"peer_address_ipv6,omitempty"`
Topology string `json:"topology,omitempty" enum:"net30,p2p,subnet"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
@@ -81,8 +81,8 @@ type OpenVPNServerEndpointOptions struct {
RemotePort uint16 `json:"remote_port,omitempty"`
MaxClients int `json:"max_clients,omitempty"`
Address badoption.Listable[netip.Prefix] `json:"address"`
PeerAddress badoption.Addr `json:"peer_address,omitempty"`
PeerAddressIPv6 badoption.Addr `json:"peer_address_ipv6,omitempty"`
PeerAddress *badoption.Addr `json:"peer_address,omitempty"`
PeerAddressIPv6 *badoption.Addr `json:"peer_address_ipv6,omitempty"`
Topology string `json:"topology,omitempty" enum:"net30,p2p,subnet"`
DuplicateCN bool `json:"duplicate_cn,omitempty"`
Users []auth.User `json:"users,omitempty"`
+2 -2
View File
@@ -405,11 +405,11 @@ func buildClientDataChannelOptions(options option.OpenVPNClientEndpointOptions)
}
func buildClientTunnelOptions(options option.OpenVPNClientEndpointOptions, requirePeerAddress bool) (ovpn.ClientTunnelOptions, error) {
vpnGateway := netip.Addr(options.PeerAddress)
vpnGateway := options.PeerAddress.Build(netip.Addr{})
if vpnGateway.IsValid() && !vpnGateway.Is4() {
return ovpn.ClientTunnelOptions{}, E.New("`peer_address` must be an IPv4 address")
}
vpnGatewayIPv6 := netip.Addr(options.PeerAddressIPv6)
vpnGatewayIPv6 := options.PeerAddressIPv6.Build(netip.Addr{})
if vpnGatewayIPv6.IsValid() && !vpnGatewayIPv6.Is6() {
return ovpn.ClientTunnelOptions{}, E.New("`peer_address_ipv6` must be an IPv6 address")
}
+3 -3
View File
@@ -297,7 +297,7 @@ func buildServerOptions(options option.OpenVPNServerEndpointOptions) (ovpn.Serve
if options.TLS == nil {
return ovpn.ServerOptions{}, E.New("missing `tls` options")
}
if len(options.StaticKey) > 0 || options.StaticKeyPath != "" || options.KeyDirection != "" || options.Cipher != "" || options.Remote != "" || options.RemotePort != 0 || netip.Addr(options.PeerAddress).IsValid() || netip.Addr(options.PeerAddressIPv6).IsValid() {
if len(options.StaticKey) > 0 || options.StaticKeyPath != "" || options.KeyDirection != "" || options.Cipher != "" || options.Remote != "" || options.RemotePort != 0 || options.PeerAddress.Build(netip.Addr{}).IsValid() || options.PeerAddressIPv6.Build(netip.Addr{}).IsValid() {
return ovpn.ServerOptions{}, E.New("static-key server options require `mode: static_key`")
}
tlsOptions, keyDirection, err := buildServerTLSOptions(*options.TLS)
@@ -367,11 +367,11 @@ func buildStaticKeyServerOptions(options option.OpenVPNServerEndpointOptions, pr
if err != nil {
return ovpn.ServerOptions{}, err
}
vpnGateway := netip.Addr(options.PeerAddress)
vpnGateway := options.PeerAddress.Build(netip.Addr{})
if vpnGateway.IsValid() && !vpnGateway.Is4() {
return ovpn.ServerOptions{}, E.New("`peer_address` must be an IPv4 address")
}
vpnGatewayIPv6 := netip.Addr(options.PeerAddressIPv6)
vpnGatewayIPv6 := options.PeerAddressIPv6.Build(netip.Addr{})
if vpnGatewayIPv6.IsValid() && !vpnGatewayIPv6.Is6() {
return ovpn.ServerOptions{}, E.New("`peer_address_ipv6` must be an IPv6 address")
}
+3 -3
View File
@@ -197,7 +197,7 @@ func TestOpenVPNStaticKeyClientDataPath(t *testing.T) {
Mode: ovpn.ModeStaticKey,
Network: N.NetworkTCP,
Address: []netip.Prefix{netip.MustParsePrefix(clientTunnelAddress + "/30")},
PeerAddress: badoption.Addr(netip.MustParseAddr(peerTunnelAddress)),
PeerAddress: common.Ptr(badoption.Addr(netip.MustParseAddr(peerTunnelAddress))),
Topology: "p2p",
StaticKeyPath: staticKeyPath,
KeyDirection: "client",
@@ -286,7 +286,7 @@ func runOpenVPNStaticKeySelfToSelf(t *testing.T, protocol string) {
RemotePort: clientOpenVPNPort,
MaxClients: 1,
Address: []netip.Prefix{netip.MustParsePrefix(serverTunnelAddress + "/30")},
PeerAddress: badoption.Addr(netip.MustParseAddr(clientTunnelAddress)),
PeerAddress: common.Ptr(badoption.Addr(netip.MustParseAddr(clientTunnelAddress))),
Topology: "p2p",
StaticKeyPath: staticKeyPath,
KeyDirection: "server",
@@ -302,7 +302,7 @@ func runOpenVPNStaticKeySelfToSelf(t *testing.T, protocol string) {
Mode: ovpn.ModeStaticKey,
Network: protocol,
Address: []netip.Prefix{netip.MustParsePrefix(clientTunnelAddress + "/30")},
PeerAddress: badoption.Addr(netip.MustParseAddr(serverTunnelAddress)),
PeerAddress: common.Ptr(badoption.Addr(netip.MustParseAddr(serverTunnelAddress))),
Topology: "p2p",
StaticKeyPath: staticKeyPath,
KeyDirection: "client",