github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/apigw/groups/requests.go (about)

     1  package groups
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  // CreateOptsBuilder allows extensions to add additional parameters to the
     8  // Create request.
     9  type CreateOptsBuilder interface {
    10  	ToGroupCreateMap() (map[string]interface{}, error)
    11  }
    12  
    13  // CreateOpts contains options for creating a API group. This object is passed to
    14  // the API groups Create function.
    15  type CreateOpts struct {
    16  	// Name of the API group
    17  	Name string `json:"name" required:"true"`
    18  	// Description of the API group
    19  	Remark string `json:"remark,omitempty"`
    20  }
    21  
    22  // ToGroupCreateMap assembles a request body based on the contents of a
    23  // CreateOpts.
    24  func (opts CreateOpts) ToGroupCreateMap() (map[string]interface{}, error) {
    25  	return golangsdk.BuildRequestBody(opts, "")
    26  }
    27  
    28  // Create will create a new API group based on the values in CreateOpts.
    29  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    30  	b, err := opts.ToGroupCreateMap()
    31  	if err != nil {
    32  		r.Err = err
    33  		return
    34  	}
    35  	_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
    36  		OkCodes: []int{200, 201},
    37  	})
    38  	return
    39  }
    40  
    41  // UpdateOptsBuilder allows extensions to add additional parameters to the
    42  // Update request.
    43  type UpdateOptsBuilder interface {
    44  	ToGroupUpdateMap() (map[string]interface{}, error)
    45  }
    46  
    47  // UpdateOpts contain options for updating an existing API group.
    48  type UpdateOpts struct {
    49  	// Name of the API group
    50  	Name string `json:"name" required:"true"`
    51  	// Description of the API group
    52  	Remark string `json:"remark,omitempty"`
    53  }
    54  
    55  // ToGroupUpdateMap assembles a request body based on the contents of an
    56  // UpdateOpts.
    57  func (opts UpdateOpts) ToGroupUpdateMap() (map[string]interface{}, error) {
    58  	return golangsdk.BuildRequestBody(opts, "")
    59  }
    60  
    61  // Update will update the API group with provided information. To extract the updated
    62  // API group from the response, call the Extract method on the UpdateResult.
    63  func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
    64  	b, err := opts.ToGroupUpdateMap()
    65  	if err != nil {
    66  		r.Err = err
    67  		return
    68  	}
    69  	_, r.Err = client.Put(groupURL(client, id), b, &r.Body, &golangsdk.RequestOpts{
    70  		OkCodes: []int{200},
    71  	})
    72  	return
    73  }
    74  
    75  // Delete will delete the existing group with the provided ID.
    76  func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
    77  	_, r.Err = client.Delete(groupURL(client, id), nil)
    78  	return
    79  }
    80  
    81  // Get retrieves the group with the provided ID. To extract the Group object
    82  // from the response, call the Extract method on the GetResult.
    83  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
    84  	_, r.Err = client.Get(groupURL(client, id), &r.Body, nil)
    85  	return
    86  }