From 9261a6063d28b6144147250e5daa076feee73625 Mon Sep 17 00:00:00 2001 From: _rave_cat_ <169521342+ravecat-dev@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:21:27 +0800 Subject: [PATCH] chore: fix typos. (#640) * chore: fix typos. * chore: makes go-staticcheck happy. --- api/proxypanel/proxypanel.go | 2 +- api/proxypanel/proypanel_test.go | 4 ++-- api/sspanel/sspanel.go | 21 +++++++++++---------- api/sspanel/sspanel_test.go | 4 ++-- panel/panel.go | 4 ++-- service/controller/inboundbuilder.go | 10 +++++----- service/controller/outboundbuilder.go | 2 +- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/api/proxypanel/proxypanel.go b/api/proxypanel/proxypanel.go index bc1f16b6..dcb4a375 100644 --- a/api/proxypanel/proxypanel.go +++ b/api/proxypanel/proxypanel.go @@ -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 diff --git a/api/proxypanel/proypanel_test.go b/api/proxypanel/proypanel_test.go index c054a394..d1a5487f 100644 --- a/api/proxypanel/proypanel_test.go +++ b/api/proxypanel/proypanel_test.go @@ -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) diff --git a/api/sspanel/sspanel.go b/api/sspanel/sspanel.go index 5f411913..258e94fa 100644 --- a/api/sspanel/sspanel.go +++ b/api/sspanel/sspanel.go @@ -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) @@ -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 @@ -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). @@ -474,7 +475,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) ( } if err != nil { - return nil, fmt.Errorf("marshal Header Type %s into config fialed: %s", header, err) + return nil, fmt.Errorf("marshal Header Type %s into config failed: %s", header, err) } // Create GeneralNodeInfo diff --git a/api/sspanel/sspanel_test.go b/api/sspanel/sspanel_test.go index 44b4a4a4..30baaff0 100644 --- a/api/sspanel/sspanel_test.go +++ b/api/sspanel/sspanel_test.go @@ -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) diff --git a/panel/panel.go b/panel/panel.go index 69c8fca3..3d4329ce 100644 --- a/panel/panel.go +++ b/panel/panel.go @@ -208,7 +208,7 @@ func (p *Panel) Start() { for _, s := range p.Service { err := s.Start() if err != nil { - log.Panicf("Panel Start fialed: %s", err) + log.Panicf("Panel Start failed: %s", err) } } p.Running = true @@ -222,7 +222,7 @@ func (p *Panel) Close() { for _, s := range p.Service { err := s.Close() if err != nil { - log.Panicf("Panel Close fialed: %s", err) + log.Panicf("Panel Close failed: %s", err) } } p.Service = nil diff --git a/service/controller/inboundbuilder.go b/service/controller/inboundbuilder.go index fcea7ef1..4340f29c 100644 --- a/service/controller/inboundbuilder.go +++ b/service/controller/inboundbuilder.go @@ -139,7 +139,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I setting, err := json.Marshal(proxySetting) if err != nil { - return nil, fmt.Errorf("marshal proxy %s config fialed: %s", nodeInfo.NodeType, err) + return nil, fmt.Errorf("marshal proxy %s config failed: %s", nodeInfo.NodeType, err) } inboundDetourConfig.Protocol = protocol inboundDetourConfig.Settings = &setting @@ -287,13 +287,13 @@ func buildVlessFallbacks(fallbackConfigs []*FallBackConfig) ([]*conf.VLessInboun for i, c := range fallbackConfigs { if c.Dest == "" { - return nil, fmt.Errorf("dest is required for fallback fialed") + return nil, fmt.Errorf("dest is required for fallback failed") } var dest json.RawMessage dest, err := json.Marshal(c.Dest) if err != nil { - return nil, fmt.Errorf("marshal dest %s config fialed: %s", dest, err) + return nil, fmt.Errorf("marshal dest %s config failed: %s", dest, err) } vlessFallBacks[i] = &conf.VLessInboundFallback{ Name: c.SNI, @@ -315,13 +315,13 @@ func buildTrojanFallbacks(fallbackConfigs []*FallBackConfig) ([]*conf.TrojanInbo for i, c := range fallbackConfigs { if c.Dest == "" { - return nil, fmt.Errorf("dest is required for fallback fialed") + return nil, fmt.Errorf("dest is required for fallback failed") } var dest json.RawMessage dest, err := json.Marshal(c.Dest) if err != nil { - return nil, fmt.Errorf("marshal dest %s config fialed: %s", dest, err) + return nil, fmt.Errorf("marshal dest %s config failed: %s", dest, err) } trojanFallBacks[i] = &conf.TrojanInboundFallback{ Name: c.SNI, diff --git a/service/controller/outboundbuilder.go b/service/controller/outboundbuilder.go index 9be461ab..6aaad4b0 100644 --- a/service/controller/outboundbuilder.go +++ b/service/controller/outboundbuilder.go @@ -38,7 +38,7 @@ func OutboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core. var setting json.RawMessage setting, err := json.Marshal(proxySetting) if err != nil { - return nil, fmt.Errorf("marshal proxy %s config fialed: %s", nodeInfo.NodeType, err) + return nil, fmt.Errorf("marshal proxy %s config failed: %s", nodeInfo.NodeType, err) } outboundDetourConfig.Settings = &setting return outboundDetourConfig.Build()