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

     1  package ptrrecords
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  // Get returns information about a ptr, given its ID.
     8  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
     9  	_, r.Err = client.Get(resourceURL(client, id), &r.Body, nil)
    10  	return
    11  }
    12  
    13  // CreateOptsBuilder allows extensions to add additional attributes to the
    14  // Create request.
    15  type CreateOptsBuilder interface {
    16  	ToPtrCreateMap() (map[string]interface{}, error)
    17  }
    18  
    19  // CreateOpts specifies the attributes used to create a ptr.
    20  type CreateOpts struct {
    21  	// Name of the ptr.
    22  	PtrName string `json:"ptrdname" required:"true"`
    23  
    24  	// Description of the ptr.
    25  	Description string `json:"description,omitempty"`
    26  
    27  	// TTL is the time to live of the ptr.
    28  	TTL int `json:"-"`
    29  
    30  	// Tags of the ptr.
    31  	Tags []Tag `json:"tags,omitempty"`
    32  
    33  	// Enterprise project id
    34  	EnterpriseProjectID string `json:"enterprise_project_id,omitempty"`
    35  }
    36  
    37  // Tag is a structure of key value pair.
    38  type Tag struct {
    39  	//tag key
    40  	Key string `json:"key" required:"true"`
    41  	//tag value
    42  	Value string `json:"value" required:"true"`
    43  }
    44  
    45  // ToPtrCreateMap formats an CreateOpts structure into a request body.
    46  func (opts CreateOpts) ToPtrCreateMap() (map[string]interface{}, error) {
    47  	b, err := golangsdk.BuildRequestBody(opts, "")
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  
    52  	if opts.TTL > 0 {
    53  		b["ttl"] = opts.TTL
    54  	}
    55  
    56  	return b, nil
    57  }
    58  
    59  // Create implements a ptr create/update request.
    60  func Create(client *golangsdk.ServiceClient, region string, fip_id string, opts CreateOptsBuilder) (r CreateResult) {
    61  	b, err := opts.ToPtrCreateMap()
    62  	if err != nil {
    63  		r.Err = err
    64  		return
    65  	}
    66  	_, r.Err = client.Patch(baseURL(client, region, fip_id), &b, &r.Body, &golangsdk.RequestOpts{
    67  		OkCodes: []int{200, 202},
    68  	})
    69  	return
    70  }
    71  
    72  // Delete implements a ptr delete request.
    73  func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
    74  	b := map[string]string{
    75  		"ptrname": "null",
    76  	}
    77  	_, r.Err = client.Patch(resourceURL(client, id), &b, nil, &golangsdk.RequestOpts{
    78  		OkCodes: []int{200, 202},
    79  	})
    80  	return
    81  }