change project structure, performance optimization

This commit is contained in:
yuzuki999
2022-08-12 18:02:06 +08:00
parent 4bd389aa05
commit ba1e088afb
51 changed files with 181 additions and 190 deletions

View File

@@ -2,9 +2,9 @@ package api
type API interface {
GetNodeInfo() (nodeInfo *NodeInfo, err error)
GetUserList() (userList *[]UserInfo, err error)
ReportUserTraffic(userTraffic *[]UserTraffic) (err error)
GetUserList() (userList []UserInfo, err error)
ReportUserTraffic(userTraffic []UserTraffic) (err error)
Describe() ClientInfo
GetNodeRule() (ruleList *[]DetectRule, protocolList *[]string, err error)
GetNodeRule() (ruleList []DetectRule, protocolList []string, err error)
Debug()
}

View File

@@ -160,10 +160,10 @@ func (c *Client) GetNodeInfo() (nodeInfo *NodeInfo, err error) {
return nodeInfo, nil
}
func (c *Client) GetNodeRule() (*[]DetectRule, *[]string, error) {
func (c *Client) GetNodeRule() ([]DetectRule, []string, error) {
ruleList := c.LocalRuleList
if c.NodeType != "V2ray" || c.RemoteRuleCache == nil {
return &ruleList, nil, nil
return ruleList, nil, nil
}
// V2board only support the rule for v2ray
// fix: reuse config response
@@ -185,7 +185,7 @@ func (c *Client) GetNodeRule() (*[]DetectRule, *[]string, error) {
}
}
c.RemoteRuleCache = nil
return &ruleList, &protocolList, nil
return ruleList, protocolList, nil
}
// ParseTrojanNodeResponse parse the response for the given nodeinfor format
@@ -211,9 +211,9 @@ func (c *Client) ParseSSNodeResponse() (*NodeInfo, error) {
if err != nil {
return nil, err
}
if len(*userInfo) > 0 {
port = (*userInfo)[0].Port
method = (*userInfo)[0].Cipher
if len(userInfo) > 0 {
port = userInfo[0].Port
method = userInfo[0].Cipher
} else {
return nil, fmt.Errorf("shadowsocks node need a active user")
}

View File

@@ -45,7 +45,7 @@ type UserListBody struct {
}
// GetUserList will pull user form sspanel
func (c *Client) GetUserList() (UserList *[]UserInfo, err error) {
func (c *Client) GetUserList() (UserList []UserInfo, err error) {
var path string
switch c.NodeType {
case "V2ray":
@@ -69,7 +69,7 @@ func (c *Client) GetUserList() (UserList *[]UserInfo, err error) {
if err != nil {
return nil, fmt.Errorf("unmarshal userlist error: %s", err)
}
return &userList.Data, nil
return userList.Data, nil
}
type UserTraffic struct {
@@ -79,7 +79,7 @@ type UserTraffic struct {
}
// ReportUserTraffic reports the user traffic
func (c *Client) ReportUserTraffic(userTraffic *[]UserTraffic) error {
func (c *Client) ReportUserTraffic(userTraffic []UserTraffic) error {
var path string
switch c.NodeType {
case "V2ray":
@@ -90,8 +90,8 @@ func (c *Client) ReportUserTraffic(userTraffic *[]UserTraffic) error {
path = "/api/v1/server/ShadowsocksTidalab/submit"
}
data := make([]UserTraffic, len(*userTraffic))
for i, traffic := range *userTraffic {
data := make([]UserTraffic, len(userTraffic))
for i, traffic := range userTraffic {
data[i] = UserTraffic{
UID: traffic.UID,
Upload: traffic.Upload,