Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
qydysky authored Nov 22, 2024
1 parent 9e86fbb commit c21385c
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,38 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) {

var backIs []*Back

backIs = append(backIs, route.FiliterBackByRequest(r)...)
{
if t, e := r.Cookie("_psign_" + cookie); e == nil {
if backP, aok := route.backMap.Load(t.Value); aok {

if ok, e := backP.(*Back).getFiliterReqUri().Match(r); e != nil {
logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", e))
} else if ok {
aok = false
}

if t, e := r.Cookie("_psign_" + cookie); e == nil {
if backP, aok := route.backMap.Load(t.Value); aok {
if ok, e := backP.(*Back).getFiliterReqHeader().Match(r.Header); e != nil {
logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", e))
} else if ok {
aok = false
}

if ok, e := backP.(*Back).getFiliterReqUri().Match(r); e != nil {
logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", e))
} else if ok {
aok = false
if aok {
for i := uint(0); i < backP.(*Back).Weight; i++ {
backIs = append(backIs, backP.(*Back))
}
}
}
}

if ok, e := backP.(*Back).getFiliterReqHeader().Match(r.Header); e != nil {
logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", e))
} else if ok {
aok = false
}
var splicingC = len(backIs)

if aok {
for i := uint(0); i < backP.(*Back).Weight; i++ {
backIs = append(backIs, backP.(*Back))
}
}
backIs = append(backIs, route.FiliterBackByRequest(r)...)

if f, ok := rollRuleMap[route.RollRule]; ok {
f(backIs[splicingC:])
} else {
rand_Shuffle(backIs[splicingC:])
}
}

Expand Down Expand Up @@ -390,12 +400,6 @@ func (t *Route) FiliterBackByRequest(r *http.Request) []*Back {
backLink = append(backLink, &t.Backs[i])
}

if f, ok := rollRuleMap[t.RollRule]; ok {
f(backLink)
} else {
rand_Shuffle(backLink)
}

return backLink
}

Expand Down

0 comments on commit c21385c

Please sign in to comment.