github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/smn/v2/subscriptions/requests.go (about) 1 package subscriptions 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/openstack" 6 ) 7 8 // CreateOptsBuilder is used for creating subscription parameters. 9 // any struct providing the parameters should implement this interface 10 type CreateOptsBuilder interface { 11 ToSubscriptionCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOpts is a struct that contains all the parameters. 15 type CreateOpts struct { 16 // Message endpoint 17 Endpoint string `json:"endpoint" required:"true"` 18 // Protocol of the message endpoint 19 Protocol string `json:"protocol" required:"true"` 20 // Description of the subscription 21 Remark string `json:"remark,omitempty"` 22 } 23 24 func (ops CreateOpts) ToSubscriptionCreateMap() (map[string]interface{}, error) { 25 return golangsdk.BuildRequestBody(ops, "") 26 } 27 28 // Create a subscription with given parameters. 29 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder, topicUrn string) (r CreateResult) { 30 b, err := opts.ToSubscriptionCreateMap() 31 if err != nil { 32 r.Err = err 33 return 34 } 35 36 _, r.Err = client.Post(createURL(client, topicUrn), b, &r.Body, &golangsdk.RequestOpts{ 37 OkCodes: []int{201, 200}, 38 MoreHeaders: openstack.StdRequestOpts().MoreHeaders, 39 }) 40 41 return 42 } 43 44 // Delete a subscription via subscription urn 45 func Delete(client *golangsdk.ServiceClient, subscriptionUrn string) (r DeleteResult) { 46 _, r.Err = client.Delete(deleteURL(client, subscriptionUrn), &golangsdk.RequestOpts{ 47 OkCodes: []int{200, 202, 204}, 48 MoreHeaders: openstack.StdRequestOpts().MoreHeaders, 49 }) 50 return 51 } 52 53 // List all the subscriptions 54 func List(client *golangsdk.ServiceClient) (r ListResult) { 55 _, r.Err = client.Get(listURL(client), &r.Body, openstack.StdRequestOpts()) 56 return 57 } 58 59 // ListFromTopic all the subscriptions from topic 60 func ListFromTopic(client *golangsdk.ServiceClient, subscriptionUrn string) (r ListResult) { 61 _, r.Err = client.Get(listFromTopicURL(client, subscriptionUrn), &r.Body, openstack.StdRequestOpts()) 62 return 63 }