github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dns/v2/ptrrecords/requests.go (about) 1 package ptrrecords 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 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 34 // Tag is a structure of key value pair. 35 type Tag struct { 36 // tag key 37 Key string `json:"key" required:"true"` 38 // tag value 39 Value string `json:"value" required:"true"` 40 } 41 42 // ToPtrCreateMap formats an CreateOpts structure into a request body. 43 func (opts CreateOpts) ToPtrCreateMap() (map[string]interface{}, error) { 44 b, err := golangsdk.BuildRequestBody(opts, "") 45 if err != nil { 46 return nil, err 47 } 48 49 if opts.TTL > 0 { 50 b["ttl"] = opts.TTL 51 } 52 53 return b, nil 54 } 55 56 // Create implements a ptr create/update request. 57 func Create(client *golangsdk.ServiceClient, region string, fip_id string, opts CreateOptsBuilder) (r CreateResult) { 58 b, err := opts.ToPtrCreateMap() 59 if err != nil { 60 r.Err = err 61 return 62 } 63 _, r.Err = client.Patch(baseURL(client, region, fip_id), &b, &r.Body, &golangsdk.RequestOpts{ 64 OkCodes: []int{200, 202}, 65 }) 66 return 67 } 68 69 // Delete implements a ptr delete request. 70 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 71 b := map[string]string{ 72 "ptrname": "null", 73 } 74 _, r.Err = client.Patch(resourceURL(client, id), &b, nil, &golangsdk.RequestOpts{ 75 OkCodes: []int{200, 202}, 76 }) 77 return 78 }