Torrent Glenn | 12bc4df | 2014-02-03 13:26:41 -0800 | [diff] [blame] | 1 | package gophercloud |
| 2 | |
| 3 | import( |
| 4 | "github.com/mitchellh/mapstructure" |
| 5 | ) |
| 6 | |
| 7 | //The default generic openstack api |
| 8 | var OpenstackApi = map[string]interface{}{ |
Mohammed Naser | 15f7ac7 | 2014-06-07 18:00:16 -0400 | [diff] [blame] | 9 | "Name": "nova", |
Torrent Glenn | 12bc4df | 2014-02-03 13:26:41 -0800 | [diff] [blame] | 10 | "UrlChoice": PublicURL, |
| 11 | } |
| 12 | |
| 13 | // Api for use with rackspace |
| 14 | var RackspaceApi = map[string]interface{}{ |
| 15 | "Name": "cloudServersOpenStack", |
| 16 | "VersionId": "2", |
| 17 | "UrlChoice": PublicURL, |
| 18 | } |
| 19 | |
| 20 | |
| 21 | //Populates an ApiCriteria struct with the api values |
| 22 | //from one of the api maps |
| 23 | func PopulateApi(variant string) (ApiCriteria, error){ |
| 24 | var Api ApiCriteria |
| 25 | var variantMap map[string]interface{} |
| 26 | |
| 27 | switch variant { |
| 28 | case "": |
| 29 | variantMap = OpenstackApi |
| 30 | |
| 31 | case "openstack": |
| 32 | variantMap = OpenstackApi |
| 33 | |
| 34 | case "rackspace": |
| 35 | variantMap = RackspaceApi |
| 36 | } |
| 37 | |
| 38 | err := mapstructure.Decode(variantMap,&Api) |
| 39 | if err != nil{ |
| 40 | return Api,err |
| 41 | } |
| 42 | return Api, err |
| 43 | } |