Skip to content

Commit

Permalink
Merge pull request #386 from BuxOrg/chore-426-BroadcastClientAPIs-as-…
Browse files Browse the repository at this point in the history
…struct

chore(BUX-426): BroadcastClientAPIs as struct
  • Loading branch information
mergify[bot] authored Dec 28, 2023
2 parents aa41772 + d7633db commit 2ec958d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
8 changes: 7 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ type NodesConfig struct {
// MinercraftCustomAPIs is a slice of Minercraft custom miners APIs.
MinercraftCustomAPIs []*minercraft.MinerAPIs `json:"minercraft_custom_apis" mapstructure:"minercraft_custom_apis"`
// BroadcastClientAPIs is a slice of Broadcast Client custom miners APIs.
BroadcastClientAPIs []string `json:"broadcast_client_apis" mapstructure:"broadcast_client_apis"`
BroadcastClientAPIs []*BroadcastClientAPI `json:"broadcast_client_apis" mapstructure:"broadcast_client_apis"`
}

// BroadcastClientAPI is a URL-Token pair for Broadcast Client; Token is optional
type BroadcastClientAPI struct {
Token string `json:"token,omitempty"`
URL string `json:"url,omitempty"`
}

// NotificationsConfig is the configuration for notifications
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func getNodesDefaults() *NodesConfig {
UseMapiFeeQuotes: true,
MinercraftAPI: "mAPI",
MinercraftCustomAPIs: []*minercraft.MinerAPIs{},
BroadcastClientAPIs: []string{},
BroadcastClientAPIs: []*BroadcastClientAPI{},
}
}

Expand Down
30 changes: 5 additions & 25 deletions config/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,28 +366,6 @@ func loadDatastore(options []bux.ClientOps, appConfig *AppConfig, testMode bool)
return options, nil
}

// splitBroadcastClientApis splits the broadcast client apis into a list of broadcast_client.ArcClientConfig
func splitBroadcastClientApis(apis []string) []broadcastclient.ArcClientConfig {
var arcClients []broadcastclient.ArcClientConfig
for _, api := range apis {
separatorIndex := strings.Index(api, "|")
if separatorIndex != -1 {
apiURL := api[:separatorIndex]
token := api[separatorIndex+1:]

arcClients = append(arcClients, broadcastclient.ArcClientConfig{
APIUrl: apiURL,
Token: token,
})
} else {
arcClients = append(arcClients, broadcastclient.ArcClientConfig{
APIUrl: api,
})
}
}
return arcClients
}

func loadTaskManager(appConfig *AppConfig, options []bux.ClientOps) []bux.ClientOps {
ops := []taskmanager.TasqOps{}
if appConfig.TaskManager.Factory == taskmanager.FactoryRedis {
Expand All @@ -401,11 +379,13 @@ func loadTaskManager(appConfig *AppConfig, options []bux.ClientOps) []bux.Client

func loadBroadcastClientAPI(appConfig *AppConfig, options []bux.ClientOps) []bux.ClientOps {
if appConfig.Nodes.BroadcastClientAPIs != nil {
arcClientConfigs := splitBroadcastClientApis(appConfig.Nodes.BroadcastClientAPIs)

builder := broadcastclient.Builder()
for _, cfg := range arcClientConfigs {
builder.WithArc(cfg)
for _, cfg := range appConfig.Nodes.BroadcastClientAPIs {
builder.WithArc(broadcastclient.ArcClientConfig{
Token: cfg.Token,
APIUrl: cfg.URL,
})
}
broadcastClient := builder.Build()
options = append(options, bux.WithBroadcastClient(broadcastClient))
Expand Down

0 comments on commit 2ec958d

Please sign in to comment.