github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dms/v1/groups/requests.go (about) 1 package groups 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // CreateOpsBuilder is used for creating group parameters. 9 // any struct providing the parameters should implement this interface 10 type CreateOpsBuilder interface { 11 ToGroupCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOps is a struct that contains all the parameters. 15 type CreateOps struct { 16 // Indicates the informations of a consumer group. 17 Groups []GroupOps `json:"groups" required:"true"` 18 } 19 20 // GroupOps is referred by CreateOps 21 type GroupOps struct { 22 // Indicates the name of a consumer group. 23 // A string of 1 to 32 characters that contain 24 // a-z, A-Z, 0-9, hyphens (-), and underscores (_). 25 Name string `json:"name" required:"true"` 26 } 27 28 // ToGroupCreateMap is used for type convert 29 func (ops CreateOps) ToGroupCreateMap() (map[string]interface{}, error) { 30 return golangsdk.BuildRequestBody(ops, "") 31 } 32 33 // Create a group with given parameters. 34 func Create(client *golangsdk.ServiceClient, queueID string, ops CreateOpsBuilder) (r CreateResult) { 35 b, err := ops.ToGroupCreateMap() 36 if err != nil { 37 r.Err = err 38 return 39 } 40 41 _, r.Err = client.Post(createURL(client, queueID), b, &r.Body, &golangsdk.RequestOpts{ 42 OkCodes: []int{201}, 43 }) 44 45 return 46 } 47 48 // Delete a group by id 49 func Delete(client *golangsdk.ServiceClient, queueID string, groupID string) (r DeleteResult) { 50 _, r.Err = client.Delete(deleteURL(client, queueID, groupID), nil) 51 return 52 } 53 54 // List all the groups 55 func List(client *golangsdk.ServiceClient, queueID string, includeDeadLetter bool) pagination.Pager { 56 url := listURL(client, queueID, includeDeadLetter) 57 58 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 59 return GroupPage{pagination.SinglePageBase(r)} 60 }) 61 }