fix some bugs

This commit is contained in:
yuzuki999
2023-06-09 12:36:49 +08:00
parent 42bb7bc90f
commit 9827d442d5
14 changed files with 103 additions and 80 deletions

View File

@@ -11,7 +11,9 @@ import (
)
type CommonNodeRsp struct {
Host string `json:"host"`
ServerPort int `json:"server_port"`
ServerName string `json:"server_name"`
Routes []Route `json:"routes"`
BaseConfig BaseConfig `json:"base_config"`
}
@@ -54,11 +56,11 @@ type NodeInfo struct {
Id int
Type string
Rules []*regexp.Regexp
Host string
Port int
Network string
NetworkSettings json.RawMessage
Tls bool
Host string
ServerName string
UpMbps int
DownMbps int
@@ -75,16 +77,14 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
if err = c.checkResponse(r, path, err); err != nil {
return
}
err = json.Unmarshal(r.Body(), &node)
if err != nil {
return
}
if c.etag == r.Header().Get("ETag") { // node info not changed
return nil, nil
}
// parse common params
node.Id = c.NodeId
node.Type = c.NodeType
node = &NodeInfo{
Id: c.NodeId,
Type: c.NodeType,
}
common := CommonNodeRsp{}
err = json.Unmarshal(r.Body(), &common)
if err != nil {
@@ -103,6 +103,9 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
}
}
}
node.ServerName = common.ServerName
node.Host = common.Host
node.Port = common.ServerPort
node.PullInterval = intervalToTime(common.BaseConfig.PullInterval)
node.PushInterval = intervalToTime(common.BaseConfig.PushInterval)
// parse protocol params

View File

@@ -43,9 +43,9 @@ func New(c *conf.ApiConfig) (*Client, error) {
client.SetBaseURL(c.APIHost)
// Check node type
c.NodeType = strings.ToLower(c.NodeType)
if c.NodeType != "v2ray" &&
c.NodeType != "trojan" &&
c.NodeType != "shadowsocks" {
switch c.NodeType {
case "v2ray", "trojan", "shadowsocks", "hysteria":
default:
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
}
// Create Key for each requests

View File

@@ -20,7 +20,7 @@ func (c *Client) checkResponse(res *resty.Response, path string, err error) erro
}
if res.StatusCode() != 200 {
body := res.Body()
return fmt.Errorf("request %s failed: %s, %s", c.assembleURL(path), string(body), err)
return fmt.Errorf("request %s failed: %s", c.assembleURL(path), string(body))
}
return nil
}