端口分配时加锁;网关上线后保存平台恢复的节点与授权数据;现在新节点连接后会按需向平台报告更新
This commit is contained in:
@@ -11,22 +11,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Online(prov, city, isp string) (id int32, host string, err error) {
|
||||
|
||||
var ispInt = 0
|
||||
switch isp {
|
||||
case "电信":
|
||||
ispInt = 1
|
||||
case "联通":
|
||||
ispInt = 2
|
||||
case "移动":
|
||||
ispInt = 3
|
||||
}
|
||||
|
||||
func Online() (id int32, host string, err error) {
|
||||
bytes, err := json.Marshal(map[string]any{
|
||||
"prov": prov,
|
||||
"city": city,
|
||||
"isp": ispInt,
|
||||
"name": env.Name,
|
||||
"version": core.Version,
|
||||
})
|
||||
@@ -39,7 +25,10 @@ func Online(prov, city, isp string) (id int32, host string, err error) {
|
||||
if err != nil {
|
||||
return 0, "", fmt.Errorf("执行请求失败: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(resp.Body)
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return 0, "", errors.New("状态码: " + resp.Status)
|
||||
}
|
||||
@@ -62,24 +51,3 @@ func Online(prov, city, isp string) (id int32, host string, err error) {
|
||||
|
||||
return respBody.Id, respBody.Host, nil
|
||||
}
|
||||
|
||||
func Offline() error {
|
||||
var bytes, err = json.Marshal(map[string]any{
|
||||
"name": env.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var body = strings.NewReader(string(bytes))
|
||||
|
||||
resp, err := http.Post(env.EndpointOffline, "application/json", body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("执行请求失败: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return errors.New("状态码: " + resp.Status)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user