v1.8.2
This commit is contained in:
37
universal-client.go
Normal file
37
universal-client.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user