github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/swr/v2/namespaces/requests.go (about)

     1  package namespaces
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{
     8  	MoreHeaders: map[string]string{"Content-Type": "application/json"},
     9  }
    10  
    11  // CreateOptsBuilder allows extensions to add additional parameters to the
    12  // Create request.
    13  type CreateOptsBuilder interface {
    14  	ToNamespaceCreateMap() (map[string]interface{}, error)
    15  }
    16  
    17  // CreateOpts contains all the values needed to create a new network
    18  type CreateOpts struct {
    19  	Namespace string `json:"namespace" required:"true"`
    20  }
    21  
    22  // ToNamespaceCreateMap builds a create request body from CreateOpts.
    23  func (opts CreateOpts) ToNamespaceCreateMap() (map[string]interface{}, error) {
    24  	return golangsdk.BuildRequestBody(opts, "")
    25  }
    26  
    27  // Create accepts a CreateOpts struct and uses the values to create a new namespace.
    28  func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    29  	b, err := opts.ToNamespaceCreateMap()
    30  	if err != nil {
    31  		r.Err = err
    32  		return
    33  	}
    34  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{201}}
    35  	_, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt)
    36  	return
    37  }
    38  
    39  // Get retrieves a particular network based on its unique ID.
    40  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
    41  	_, r.Err = c.Get(resourceURL(c, id), &r.Body, &golangsdk.RequestOpts{
    42  		OkCodes:     []int{200},
    43  		MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil,
    44  	})
    45  	return
    46  }
    47  
    48  // Delete will permanently delete a particular network based on its unique ID.
    49  func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
    50  	_, r.Err = c.Delete(resourceURL(c, id), &golangsdk.RequestOpts{
    51  		OkCodes:     []int{204},
    52  		MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil,
    53  	})
    54  	return
    55  }