From: qydysky Date: Fri, 18 Oct 2024 16:53:53 +0000 (+0800) Subject: 1 X-Git-Tag: v0.1.20241018165530 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=290c34f71e3ab56783abf64907380e1d351d50b4;p=front%2F.git 1 --- diff --git a/config.go b/config.go index bb71c6b..17be106 100755 --- a/config.go +++ b/config.go @@ -173,6 +173,10 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) { continue } + backIs[i].lock.Lock() + backIs[i].lastChosenT = time.Now() + backIs[i].lock.Unlock() + if !strings.Contains(backIs[i].To, "://") { e = component2.Get[reqDealer]("local").Deal(r.Context(), w, r, routePath, backIs[i], logger, t.BlocksI) } else if strings.ToLower((r.Header.Get("Upgrade"))) == "websocket" { @@ -292,7 +296,6 @@ func (t *Route) SwapSign(logger Logger) { logger.Info(`I:`, fmt.Sprintf("%v > %v > %v", t.config.Addr, t.Path, t.Backs[i].Name)) t.backMap.Store(t.Backs[i].Id(), &t.Backs[i]) } - t.Backs[i].index = i t.Backs[i].SwapSign(logger) } } @@ -318,19 +321,19 @@ func (t *Route) FiliterBackByRequest(r *http.Request) []*Back { } type Back struct { - route *Route `json:"-"` - lock sync.RWMutex `json:"-"` - upT time.Time `json:"-"` - index int `json:"-"` - disableC uint `json:"-"` - dealingC uint `json:"-"` - chosenC uint `json:"-"` + route *Route `json:"-"` + lock sync.RWMutex `json:"-"` + upT time.Time `json:"-"` + lastChosenT time.Time `json:"-"` + disableC uint `json:"-"` + dealingC uint `json:"-"` + chosenC uint `json:"-"` lastResDru time.Duration `json:"-"` Name string `json:"name"` To string `json:"to"` - Weight uint `json:"weight"` + Weight uint `json:"weight,string"` AlwaysUp bool `json:"alwaysUp"` Setting @@ -347,6 +350,7 @@ func (t *Back) SwapSign(logger Logger) { } else { t.verifyPeerCer, t.verifyPeerCerErr = os.ReadFile(path) } + t.lastChosenT = time.Now() t.AlwaysUp = len(t.route.Backs) == 1 || t.AlwaysUp } diff --git a/rollRule.go b/rollRule.go index c7b4642..fc9d00d 100644 --- a/rollRule.go +++ b/rollRule.go @@ -30,7 +30,7 @@ func init() { rollRuleMap[`loop`] = func(backLink []*Back) { slices.SortStableFunc(backLink, func(a, b *Back) int { - return a.index - b.index + return a.lastChosenT.Compare(b.lastChosenT) }) } }