feat: add HA candidate failover to API server backend
- BackendConfig.Peers []string carries host:port candidates from YAML (backend.peers) - RegisterToBackend iterates Peers in order, connecting to first responsive primary - parsePeer extracted to peers.go (no build tag) so it's testable without CGO - Single-host path (no Peers) preserved unchanged - Tests: parsePeer table-driven (11 cases), stub RegisterToBackend with/without peers
This commit is contained in:
parent
9bc84f1ca1
commit
99d13f5254
7 changed files with 213 additions and 16 deletions
|
|
@ -13,10 +13,15 @@ import (
|
|||
)
|
||||
|
||||
type BackendConfig struct {
|
||||
Address string `yaml:"address"`
|
||||
Port int `yaml:"port"`
|
||||
From string `yaml:"from"`
|
||||
Key string `yaml:"key"`
|
||||
Address string `yaml:"address"`
|
||||
Port int `yaml:"port"`
|
||||
From string `yaml:"from"`
|
||||
Key string `yaml:"key"`
|
||||
// Peers lists additional controller candidates for HA mode in "host:port"
|
||||
// format. When non-empty, RegisterToBackend iterates all candidates and
|
||||
// connects to whichever responds as primary. Address+Port remain the
|
||||
// single-host fallback when Peers is empty.
|
||||
Peers []string `yaml:"peers"`
|
||||
}
|
||||
|
||||
type AppServerConfig struct {
|
||||
|
|
@ -250,6 +255,7 @@ func InitConf() error {
|
|||
Port: viper.GetInt("backend.port"),
|
||||
From: viper.GetString("backend.from"),
|
||||
Key: viper.GetString("backend.key"),
|
||||
Peers: viper.GetStringSlice("backend.peers"),
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue