mirror of
https://github.com/bolucat/Archive.git
synced 2025-12-24 13:28:37 +08:00
Update On Sun Mar 17 19:25:58 CET 2024
This commit is contained in:
@@ -3,37 +3,10 @@ package http
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func ShouldRetry(err error) bool {
|
||||
if err == nil {
|
||||
// 没有错误,无需重试
|
||||
return false
|
||||
}
|
||||
|
||||
// 如果错误实现了 net.Error 接口,我们可以进一步检查
|
||||
var netErr net.Error
|
||||
if errors.As(err, &netErr) {
|
||||
return netErr.Timeout() || netErr.Temporary()
|
||||
}
|
||||
|
||||
// 对于某些特定的系统调用错误,也可以考虑重试
|
||||
var sysErr syscall.Errno
|
||||
if errors.As(err, &sysErr) {
|
||||
switch sysErr {
|
||||
case syscall.ECONNRESET, syscall.ECONNABORTED:
|
||||
// 例:连接被重置或中止
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func PostJson(c *http.Client, url string, dataStruct interface{}) error {
|
||||
buf := new(bytes.Buffer)
|
||||
if err := json.NewEncoder(buf).Encode(dataStruct); err != nil {
|
||||
|
||||
@@ -153,7 +153,8 @@ func (xs *XrayServer) Start(ctx context.Context) error {
|
||||
case <-ticker.C:
|
||||
newCfg := config.NewConfig(xs.cfg.PATH)
|
||||
if err := newCfg.LoadConfig(); err != nil {
|
||||
xs.l.Error("Reload Config meet error", zap.Error(err))
|
||||
// TODO refine
|
||||
xs.l.Error("Reload Config meet error will retry in next loop", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
if needReload, err := xs.needReload(newCfg); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user