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

@ -738,10 +738,10 @@ func (c *APIClient) ParseUserListResponse(userInfoResponse *[]UserResponse) (*[]
// Only available for SSPanel version >= 2021.11
func (c *APIClient) ParseSSPanelNodeInfo(nodeInfoResponse *NodeInfoResponse) (*api.NodeInfo, error) {
var (
speedLimit uint64 = 0
enableTLS, enableVless bool
alterID uint16 = 0
tlsType, transportProtocol string
speedLimit uint64 = 0
enableTLS, enableVless bool
alterID uint16 = 0
transportProtocol string
)
// Check if custom_config is null
@ -773,8 +773,8 @@ func (c *APIClient) ParseSSPanelNodeInfo(nodeInfoResponse *NodeInfoResponse) (*a
transportProtocol = "tcp"
case "V2ray":
transportProtocol = nodeConfig.Network
tlsType = nodeConfig.Security
tlsType := nodeConfig.Security
if tlsType == "tls" || tlsType == "xtls" {
enableTLS = true
}
@ -784,13 +784,8 @@ func (c *APIClient) ParseSSPanelNodeInfo(nodeInfoResponse *NodeInfoResponse) (*a
}
case "Trojan":
enableTLS = true
tlsType = "tls"
transportProtocol = "tcp"
if nodeConfig.Security != "" {
tlsType = nodeConfig.Security // try to read security from config
}
// Select transport protocol
if nodeConfig.Network != "" {
transportProtocol = nodeConfig.Network // try to read transport protocol from config