Ash Wilson | b73b7f8 | 2014-08-29 15:38:06 -0400 | [diff] [blame] | 1 | package services |
| 2 | |
| 3 | import ( |
| 4 | "github.com/racker/perigee" |
| 5 | "github.com/rackspace/gophercloud" |
| 6 | ) |
| 7 | |
| 8 | // Create adds a new service of the requested type to the catalog. |
| 9 | func Create(client *gophercloud.ServiceClient, serviceType string) (*ServiceResult, error) { |
| 10 | type request struct { |
| 11 | Type string `json:"type"` |
| 12 | } |
| 13 | |
| 14 | type response struct { |
| 15 | Service ServiceResult `json:"service"` |
| 16 | } |
| 17 | |
| 18 | req := request{Type: serviceType} |
| 19 | var resp response |
| 20 | |
| 21 | _, err := perigee.Request("POST", getListURL(client), perigee.Options{ |
Ash Wilson | a87ee06 | 2014-09-03 11:26:06 -0400 | [diff] [blame^] | 22 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Ash Wilson | b73b7f8 | 2014-08-29 15:38:06 -0400 | [diff] [blame] | 23 | ReqBody: &req, |
| 24 | Results: &resp, |
| 25 | OkCodes: []int{201}, |
| 26 | }) |
| 27 | if err != nil { |
| 28 | return nil, err |
| 29 | } |
| 30 | |
| 31 | return &resp.Service, nil |
| 32 | } |