Skip to content

Commit

Permalink
feat(circuit): add circuit breaker init config
Browse files Browse the repository at this point in the history
Signed-off-by: cbluebird <[email protected]>
  • Loading branch information
cbluebird committed Jan 24, 2025
1 parent b6bc133 commit b9e317e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 19 additions & 2 deletions app/utils/circuitBreaker/circuitBreaker.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
package circuitBreaker

import "wejh-go/config/api/funnelApi"
import (
liveNessConfig "wejh-go/config/LiveNess"
"wejh-go/config/api/funnelApi"
)

var CB CircuitBreaker

func init() {
//Todo: add config
lb := LoadBalance{
zfLB: &randomLB{},
oauthLB: &randomLB{},
}
for _, config := range liveNessConfig.GetLoadBalanceConfig() {
if config.Type == funnelApi.Oauth {
lb.oauthLB.Add(config.Url)
} else if config.Type == funnelApi.ZF {
lb.zfLB.Add(config.Url)
}
}
CB = CircuitBreaker{
lb: lb,
SnapShot: make(map[string]*apiSnapShot),
}
}

type CircuitBreaker struct {
Expand Down
6 changes: 3 additions & 3 deletions config/LiveNess/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func GetLiveNessConfig() LiveNessProbeConfig {
}

type LoadBalanceConfig struct {
Name string
Url string
Type funnelApi.LoginType
Name string `json:"name"`
Url string `json:"url"`
Type funnelApi.LoginType `json:"type"`
}

func GetLoadBalanceConfig() []LoadBalanceConfig {
Expand Down

0 comments on commit b9e317e

Please sign in to comment.