forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_fetch.go
49 lines (39 loc) · 968 Bytes
/
api_fetch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package gophercloud
import(
"fmt"
"github.com/mitchellh/mapstructure"
)
//The default generic openstack api
var OpenstackApi = map[string]interface{}{
"Type": "compute",
"UrlChoice": PublicURL,
}
// Api for use with rackspace
var RackspaceApi = map[string]interface{}{
"Name": "cloudServersOpenStack",
"VersionId": "2",
"UrlChoice": PublicURL,
}
//Populates an ApiCriteria struct with the api values
//from one of the api maps
func PopulateApi(variant string) (ApiCriteria, error){
var Api ApiCriteria
var variantMap map[string]interface{}
switch variant {
case "":
variantMap = OpenstackApi
case "openstack":
variantMap = OpenstackApi
case "rackspace":
variantMap = RackspaceApi
default:
var err = fmt.Errorf(
"PopulateApi: Unknown variant %# v; legal values: \"openstack\", \"rackspace\"", variant)
return Api, err
}
err := mapstructure.Decode(variantMap,&Api)
if err != nil{
return Api,err
}
return Api, err
}