github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dms/v1/topics/requests.go (about)

     1  package topics
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  )
     6  
     7  type CreateOptsBuilder interface {
     8  	ToTopicCreateMap() (map[string]interface{}, error)
     9  }
    10  
    11  type DeleteOptsBuilder interface {
    12  	ToTopicDeleteMap() (map[string]interface{}, error)
    13  }
    14  
    15  type CreateOpts struct {
    16  	Name             string `json:"id" required:"true"`
    17  	Partition        int    `json:"partition,omitempty"`
    18  	Replication      int    `json:"replication,omitempty"`
    19  	SyncReplication  bool   `json:"sync_replication,omitempty"`
    20  	RetentionTime    int    `json:"retention_time,omitempty"`
    21  	SyncMessageFlush bool   `json:"sync_message_flush,omitempty"`
    22  }
    23  
    24  func (opts CreateOpts) ToTopicCreateMap() (map[string]interface{}, error) {
    25  	return golangsdk.BuildRequestBody(opts, "")
    26  }
    27  
    28  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder, instanceId string) (r CreateResult) {
    29  	b, err := opts.ToTopicCreateMap()
    30  	if err != nil {
    31  		r.Err = err
    32  		return
    33  	}
    34  	_, r.Err = client.Post(createURL(client, instanceId), b, &r.Body, &golangsdk.RequestOpts{
    35  		OkCodes: []int{200},
    36  	})
    37  	return
    38  }
    39  
    40  func Get(client *golangsdk.ServiceClient, instanceId string) (r GetResult) {
    41  	_, r.Err = client.Get(getURL(client, instanceId), &r.Body, nil)
    42  	return
    43  }
    44  
    45  type DeleteOpts struct {
    46  	Topics []string `json:"topics" required:"true"`
    47  }
    48  
    49  func (opts DeleteOpts) ToTopicDeleteMap() (map[string]interface{}, error) {
    50  	return golangsdk.BuildRequestBody(opts, "")
    51  }
    52  
    53  func Delete(client *golangsdk.ServiceClient, opts DeleteOptsBuilder, instanceId string) (r DeleteResult) {
    54  	b, err := opts.ToTopicDeleteMap()
    55  	if err != nil {
    56  		r.Err = err
    57  		return
    58  	}
    59  	_, r.Err = client.Post(deleteURL(client, instanceId), b, &r.Body, &golangsdk.RequestOpts{
    60  		OkCodes: []int{200},
    61  	})
    62  	return
    63  }