实现节点下线功能,优化控制通道和数据通道的连接处理

This commit is contained in:
2025-05-16 16:59:33 +08:00
parent 8a6a4833d4
commit 22f3c37478
7 changed files with 136 additions and 120 deletions

View File

@@ -69,5 +69,27 @@ func Online(prov, city, isp string) (id int32, host string, err error) {
}
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))
req, err := http.NewRequest("POST", env.EndpointOffline, body)
if err != nil {
return fmt.Errorf("创建请求失败: %w", err)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("执行请求失败: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return errors.New("状态码: " + resp.Status)
}
return nil
}