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

     1  package topics
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/pagination"
     6  )
     7  
     8  type Topic struct {
     9  	RequestId string `json:"request_id"`
    10  	TopicUrn  string `json:"topic_urn"`
    11  }
    12  
    13  type TopicGet struct {
    14  	TopicUrn            string `json:"topic_urn"`
    15  	DisplayName         string `json:"display_name"`
    16  	Name                string `json:"name"`
    17  	PushPolicy          int    `json:"push_policy"`
    18  	UpdateTime          string `json:"update_time"`
    19  	CreateTime          string `json:"create_time"`
    20  	EnterpriseProjectId string `json:"enterprise_project_id"`
    21  }
    22  
    23  type Policies struct {
    24  	AccessPolicy string `json:"access_policy"`
    25  	Introduction string `json:"introduction"`
    26  }
    27  
    28  // Extract will get the topic object out of the commonResult object.
    29  func (r commonResult) Extract() (*Topic, error) {
    30  	var s Topic
    31  	err := r.ExtractInto(&s)
    32  	return &s, err
    33  }
    34  
    35  func (r commonResult) ExtractGet() (*TopicGet, error) {
    36  	var s TopicGet
    37  	err := r.ExtractInto(&s)
    38  	return &s, err
    39  }
    40  
    41  func (r commonResult) ExtractInto(v interface{}) error {
    42  	return r.Result.ExtractIntoStructPtr(v, "")
    43  }
    44  
    45  type commonResult struct {
    46  	golangsdk.Result
    47  }
    48  
    49  // CreateResult contains the response body and error from a Create request.
    50  type CreateResult struct {
    51  	commonResult
    52  }
    53  
    54  type DeleteResult struct {
    55  	golangsdk.ErrResult
    56  }
    57  
    58  type GetResult struct {
    59  	commonResult
    60  }
    61  
    62  type UpdateResult struct {
    63  	commonResult
    64  }
    65  
    66  type ListResult struct {
    67  	golangsdk.Result
    68  }
    69  
    70  type GetPoliciesResult struct {
    71  	commonResult
    72  }
    73  
    74  func (lr ListResult) Extract() ([]TopicGet, error) {
    75  	var a struct {
    76  		Topics []TopicGet `json:"topics"`
    77  	}
    78  	err := lr.Result.ExtractInto(&a)
    79  	return a.Topics, err
    80  }
    81  
    82  type TopicPage struct {
    83  	pagination.OffsetPageBase
    84  }
    85  
    86  func (b TopicPage) IsEmpty() (bool, error) {
    87  	arr, err := ExtractTopics(b)
    88  	return len(arr) == 0, err
    89  }
    90  
    91  func ExtractTopics(r pagination.Page) ([]TopicGet, error) {
    92  	var s struct {
    93  		Topics []TopicGet `json:"topics"`
    94  	}
    95  	err := (r.(TopicPage)).ExtractInto(&s)
    96  	return s.Topics, err
    97  }
    98  
    99  func (r GetPoliciesResult) Extract() (Policies, error) {
   100  	var a struct {
   101  		Policies Policies `json:"attributes"`
   102  	}
   103  	err := r.Result.ExtractInto(&a)
   104  	return a.Policies, err
   105  }