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