github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/smn/v2/topicattributes/requests.go (about)

     1  package topicattributes
     2  
     3  import "github.com/opentelekomcloud/gophertelekomcloud"
     4  
     5  func commonOpts() *golangsdk.RequestOpts {
     6  	return &golangsdk.RequestOpts{
     7  		OkCodes: []int{200},
     8  	}
     9  }
    10  
    11  type ListOptsBuilder interface {
    12  	ToAttributeListQuery() (string, error)
    13  }
    14  
    15  type ListOpts struct {
    16  	Name string `q:"name"`
    17  }
    18  
    19  func (opts ListOpts) ToAttributeListQuery() (string, error) {
    20  	q, err := golangsdk.BuildQueryString(opts)
    21  	if err != nil {
    22  		return "", err
    23  	}
    24  	return q.String(), nil
    25  }
    26  
    27  func List(client *golangsdk.ServiceClient, topicURN string, opts ListOptsBuilder) (r GetResult) {
    28  	url := listURL(client, topicURN)
    29  	if opts != nil {
    30  		q, err := opts.ToAttributeListQuery()
    31  		if err != nil {
    32  			r.Err = err
    33  			return
    34  		}
    35  		url += q
    36  	}
    37  	_, r.Err = client.Get(url, &r.Body, nil)
    38  	return
    39  }
    40  
    41  type UpdateOptsBuilder interface {
    42  	ToAttributeUpdateMap() (map[string]interface{}, error)
    43  }
    44  
    45  type UpdateOpts struct {
    46  	Value string `json:"value"`
    47  }
    48  
    49  func (opts UpdateOpts) ToAttributeUpdateMap() (map[string]interface{}, error) {
    50  	return golangsdk.BuildRequestBody(opts, "")
    51  }
    52  
    53  func Update(client *golangsdk.ServiceClient, topicURN, attribute string, opts UpdateOptsBuilder) (r UpdateResult) {
    54  	b, err := opts.ToAttributeUpdateMap()
    55  	if err != nil {
    56  		r.Err = err
    57  		return
    58  	}
    59  	_, r.Err = client.Put(attributeURL(client, topicURN, attribute), b, &r.Body, commonOpts())
    60  	return
    61  }
    62  
    63  func Delete(client *golangsdk.ServiceClient, topicURN, attribute string) (r DeleteResult) {
    64  	_, r.Err = client.Delete(attributeURL(client, topicURN, attribute), commonOpts())
    65  	return
    66  }