Refactor variable assignments in sspanel.go

Simplified the variable assignment logic in sspanel.go to increase code efficiency and readability. "tlsType" is now conditionally initialized once instead of reset multiple times, and it is also properly scoped. Removed an unnecessary check for "nodeConfig.Security" in the "Trojan" case as this value is already taken into account in the efficient, updated logic.
This commit is contained in:
Senis 2023-11-08 19:25:55 +08:00
parent 4e48fdbe61
commit 76076b2d6a

View File

@ -741,7 +741,7 @@ func (c *APIClient) ParseSSPanelNodeInfo(nodeInfoResponse *NodeInfoResponse) (*a
speedLimit uint64 = 0 speedLimit uint64 = 0
enableTLS, enableVless bool enableTLS, enableVless bool
alterID uint16 = 0 alterID uint16 = 0
tlsType, transportProtocol string transportProtocol string
) )
// Check if custom_config is null // Check if custom_config is null
@ -773,8 +773,8 @@ func (c *APIClient) ParseSSPanelNodeInfo(nodeInfoResponse *NodeInfoResponse) (*a
transportProtocol = "tcp" transportProtocol = "tcp"
case "V2ray": case "V2ray":
transportProtocol = nodeConfig.Network transportProtocol = nodeConfig.Network
tlsType = nodeConfig.Security
tlsType := nodeConfig.Security
if tlsType == "tls" || tlsType == "xtls" { if tlsType == "tls" || tlsType == "xtls" {
enableTLS = true enableTLS = true
} }
@ -784,13 +784,8 @@ func (c *APIClient) ParseSSPanelNodeInfo(nodeInfoResponse *NodeInfoResponse) (*a
} }
case "Trojan": case "Trojan":
enableTLS = true enableTLS = true
tlsType = "tls"
transportProtocol = "tcp" transportProtocol = "tcp"
if nodeConfig.Security != "" {
tlsType = nodeConfig.Security // try to read security from config
}
// Select transport protocol // Select transport protocol
if nodeConfig.Network != "" { if nodeConfig.Network != "" {
transportProtocol = nodeConfig.Network // try to read transport protocol from config transportProtocol = nodeConfig.Network // try to read transport protocol from config