You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dynamix-golang-sdk/universal-client.go

38 lines
1.1 KiB

2 months ago
package decortsdk
import (
"fmt"
"reflect"
1 month ago
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v10/config"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v10/pkg/cloudapi"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v10/pkg/cloudbroker"
2 months ago
)
type ClientInterface interface {
CloudAPI() *cloudapi.CloudAPI
CloudBroker() *cloudbroker.CloudBroker
}
func NewUniversal(cfg config.UniversalConfig) (ClientInterface, error) {
countConfigs := 0
var client ClientInterface
switch {
case cfg.Decs3oConfig != nil && reflect.TypeOf(*cfg.Decs3oConfig) == reflect.TypeOf(config.Config{}):
client = New(*cfg.Decs3oConfig)
countConfigs++
case cfg.BVSConfig != nil && reflect.TypeOf(*cfg.BVSConfig) == reflect.TypeOf(config.BVSConfig{}):
client = NewBVS(*cfg.BVSConfig)
countConfigs++
case cfg.LegacyConfig != nil && reflect.TypeOf(*cfg.LegacyConfig) == reflect.TypeOf(config.LegacyConfig{}):
client = NewLegacy(*cfg.LegacyConfig)
countConfigs++
}
if countConfigs != 1 {
return nil, fmt.Errorf("only 1 config can be used at a time")
}
return client, nil
}