Skip to content

Commit

Permalink
chore: makes go-staticcheck happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
ravecat-dev committed May 11, 2024
1 parent 1bb4815 commit b8e38fc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api/proxypanel/proxypanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {

if err != nil {
res, _ := json.Marshal(response.Data)
return nil, fmt.Errorf("Parse node info failed: %s, \nError: %s", string(res), err)
return nil, fmt.Errorf("parse node info failed: %s, \nError: %s", string(res), err)
}

return nodeInfo, nil
Expand Down
4 changes: 2 additions & 2 deletions api/proxypanel/proypanel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func TestReportIllegal(t *testing.T) {
client := CreateClient()

detectResult := []api.DetectResult{
{1, 1},
{1, 2},
{UID: 1, RuleID: 1},
{UID: 1, RuleID: 2},
}
client.Debug()
err := client.ReportIllegal(&detectResult)
Expand Down
19 changes: 10 additions & 9 deletions api/sspanel/sspanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ func readLocalRuleList(path string) (LocalRuleList []api.DetectRule) {
if path != "" {
// open the file
file, err := os.Open(path)
defer file.Close()

defer func(file *os.File) {
err := file.Close()
if err != nil {
log.Printf("Error when closing file: %s", err)
}
}(file)
// handle errors while opening
if err != nil {
log.Printf("Error when opening file: %s", err)
Expand Down Expand Up @@ -210,13 +215,13 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
nodeInfo, err = c.ParseSSPanelNodeInfo(nodeInfoResponse)
if err != nil {
res, _ := json.Marshal(nodeInfoResponse)
return nil, fmt.Errorf("Parse node info failed: %s, \nError: %s, \nPlease check the doc of custom_config for help: https://xrayr-project.github.io/XrayR-doc/dui-jie-sspanel/sspanel/sspanel_custom_config", string(res), err)
return nil, fmt.Errorf("parse node info failed: %s, \nError: %s, \nPlease check the doc of custom_config for help: https://xrayr-project.github.io/XrayR-doc/dui-jie-sspanel/sspanel/sspanel_custom_config", string(res), err)
}
}

if err != nil {
res, _ := json.Marshal(nodeInfoResponse)
return nil, fmt.Errorf("Parse node info failed: %s, \nError: %s", string(res), err)
return nil, fmt.Errorf("parse node info failed: %s, \nError: %s", string(res), err)
}

return nodeInfo, nil
Expand Down Expand Up @@ -291,16 +296,12 @@ func (c *APIClient) ReportNodeOnlineUsers(onlineUserList *[]api.OnlineUser) erro
data := make([]OnlineUser, len(*onlineUserList))
for i, user := range *onlineUserList {
data[i] = OnlineUser{UID: user.UID, IP: user.IP}
if _, ok := reportOnline[user.UID]; ok {
reportOnline[user.UID]++
} else {
reportOnline[user.UID] = 1
}
reportOnline[user.UID]++ // will start from 1 if key doesn’t exist
}
c.LastReportOnline = reportOnline // Update LastReportOnline

postData := &PostData{Data: data}
path := fmt.Sprintf("/mod_mu/users/aliveip")
path := "/mod_mu/users/aliveip"
res, err := c.client.R().
SetQueryParam("node_id", strconv.Itoa(c.NodeID)).
SetBody(postData).
Expand Down
4 changes: 2 additions & 2 deletions api/sspanel/sspanel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func TestReportIllegal(t *testing.T) {
client := CreateClient()

detectResult := []api.DetectResult{
{1, 2},
{1, 3},
{UID: 1, RuleID: 2},
{UID: 1, RuleID: 3},
}
client.Debug()
err := client.ReportIllegal(&detectResult)
Expand Down

0 comments on commit b8e38fc

Please sign in to comment.