github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/smn/v2/subscriptions/results.go (about)

     1  package subscriptions
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/pagination"
     6  )
     7  
     8  type Subscription struct {
     9  	RequestId       string `json:"request_id"`
    10  	SubscriptionUrn string `json:"subscription_urn"`
    11  }
    12  
    13  type SubscriptionGet struct {
    14  	TopicUrn        string `json:"topic_urn"`
    15  	Protocol        string `json:"protocol"`
    16  	SubscriptionUrn string `json:"subscription_urn"`
    17  	Owner           string `json:"owner"`
    18  	Endpoint        string `json:"endpoint"`
    19  	Remark          string `json:"remark"`
    20  	Status          int    `json:"status"`
    21  }
    22  
    23  // Extract will get the subscription object out of the commonResult object.
    24  func (r commonResult) Extract() (*Subscription, error) {
    25  	var s Subscription
    26  	err := r.ExtractInto(&s)
    27  	return &s, err
    28  }
    29  
    30  func (r commonResult) ExtractInto(v interface{}) error {
    31  	return r.Result.ExtractIntoStructPtr(v, "")
    32  }
    33  
    34  type commonResult struct {
    35  	golangsdk.Result
    36  }
    37  
    38  // CreateResult contains the response body and error from a Create request.
    39  type CreateResult struct {
    40  	commonResult
    41  }
    42  
    43  type DeleteResult struct {
    44  	golangsdk.ErrResult
    45  }
    46  
    47  type GetResult struct {
    48  	commonResult
    49  }
    50  
    51  type ListResult struct {
    52  	golangsdk.Result
    53  }
    54  
    55  func (lr ListResult) Extract() ([]SubscriptionGet, error) {
    56  	var a struct {
    57  		Subscriptions []SubscriptionGet `json:"subscriptions"`
    58  	}
    59  	err := lr.Result.ExtractInto(&a)
    60  	return a.Subscriptions, err
    61  }
    62  
    63  type SubscriptionPage struct {
    64  	pagination.OffsetPageBase
    65  }
    66  
    67  func (b SubscriptionPage) IsEmpty() (bool, error) {
    68  	arr, err := ExtractSubscriptions(b)
    69  	return len(arr) == 0, err
    70  }
    71  
    72  func ExtractSubscriptions(r pagination.Page) ([]SubscriptionGet, error) {
    73  	var s struct {
    74  		Subscriptions []SubscriptionGet `json:"subscriptions"`
    75  	}
    76  	err := (r.(SubscriptionPage)).ExtractInto(&s)
    77  	return s.Subscriptions, err
    78  }