feat: add fill-first routing strategy

This commit is contained in:
gwizz
2025-12-22 17:40:35 +11:00
parent 27b43ed63f
commit b078be4613
4 changed files with 72 additions and 19 deletions

View File

@@ -5,6 +5,7 @@ package cliproxy
import (
"fmt"
"strings"
"github.com/router-for-me/CLIProxyAPI/v6/internal/api"
sdkaccess "github.com/router-for-me/CLIProxyAPI/v6/sdk/access"
@@ -197,7 +198,20 @@ func (b *Builder) Build() (*Service, error) {
if dirSetter, ok := tokenStore.(interface{ SetBaseDir(string) }); ok && b.cfg != nil {
dirSetter.SetBaseDir(b.cfg.AuthDir)
}
coreManager = coreauth.NewManager(tokenStore, nil, nil)
strategy := ""
if b.cfg != nil {
strategy = strings.ToLower(strings.TrimSpace(b.cfg.Routing.Strategy))
}
var selector coreauth.Selector
switch strategy {
case "round-robin", "roundrobin", "rr":
selector = &coreauth.RoundRobinSelector{}
default:
selector = &coreauth.FillFirstSelector{}
}
coreManager = coreauth.NewManager(tokenStore, selector, nil)
}
// Attach a default RoundTripper provider so providers can opt-in per-auth transports.
coreManager.SetRoundTripperProvider(newDefaultRoundTripperProvider())