This commit is contained in:
2024-06-28 10:54:20 +03:00
parent 9a7a7b6f36
commit 8eeef825c0
7 changed files with 201 additions and 34 deletions

37
universal-client.go Normal file
View File

@@ -0,0 +1,37 @@
package decortsdk
import (
"fmt"
"reflect"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
)
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
}