github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/apigw/v2/throttles/results.go (about)

     1  package throttles
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  type commonResult struct {
     9  	golangsdk.Result
    10  }
    11  
    12  // CreateResult represents a result of the Create method.
    13  type CreateResult struct {
    14  	commonResult
    15  }
    16  
    17  // UpdateResult represents a result of the Update method.
    18  type UpdateResult struct {
    19  	commonResult
    20  }
    21  
    22  // GetResult represents a result of the Get method.
    23  type GetResult struct {
    24  	commonResult
    25  }
    26  
    27  type ThrottlingPolicy struct {
    28  	// Number of APIs to which the request throttling policy has been bound.
    29  	BindNum int `json:"bind_num"`
    30  	// Indicates whether an excluded request throttling configuration has been created.
    31  	// 1: yes
    32  	// 2: no
    33  	IsIncludeSpecialThrottle int `json:"is_include_special_throttle"`
    34  	// Creation time.
    35  	CreateTime string `json:"create_time"`
    36  	// Description.
    37  	Description string `json:"remark"`
    38  	// Type of the request throttling policy.
    39  	// 1: exclusive, limiting the maximum number of times a single API bound to the policy can be called within
    40  	// the specified period.
    41  	// 2: shared, limiting the maximum number of times all APIs bound to the policy can be called within the
    42  	// specified period.
    43  	Type int `json:"type"`
    44  	// Period of time for limiting the number of API calls.
    45  	TimeInterval int `json:"time_interval"`
    46  	// Maximum number of times the API can be accessed by an IP address within the same period.
    47  	IpCallLimits int `json:"ip_call_limits"`
    48  	// Maximum number of times the API can be accessed by an app within the same period.
    49  	AppCallLimits int `json:"app_call_limits"`
    50  	// Request throttling policy name.
    51  	Name string `json:"name"`
    52  	// Time unit for limiting the number of API calls.
    53  	// The valid values are as following:
    54  	//     SECOND
    55  	//     MINUTE
    56  	//     HOUR
    57  	//     DAY
    58  	TimeUnit string `json:"time_unit"`
    59  	// Maximum number of times an API can be accessed within a specified period.
    60  	ApiCallLimits int `json:"api_call_limits"`
    61  	// Request throttling policy ID.
    62  	Id string `json:"id"`
    63  	// Maximum number of times the API can be accessed by a user within the same period.
    64  	UserCallLimits int `json:"user_call_limits"`
    65  }
    66  
    67  func (r commonResult) Extract() (*ThrottlingPolicy, error) {
    68  	var s ThrottlingPolicy
    69  	err := r.ExtractInto(&s)
    70  	return &s, err
    71  }
    72  
    73  // The ThorttlePage represents the result of a List operation.
    74  type ThorttlePage struct {
    75  	pagination.SinglePageBase
    76  }
    77  
    78  // ExtractPolicies its Extract method to interpret it as a throttling policy array.
    79  func ExtractPolicies(r pagination.Page) ([]ThrottlingPolicy, error) {
    80  	var s []ThrottlingPolicy
    81  	err := r.(ThorttlePage).Result.ExtractIntoSlicePtr(&s, "throttles")
    82  	return s, err
    83  }
    84  
    85  type DeleteResult struct {
    86  	golangsdk.ErrResult
    87  }
    88  
    89  // SpecThrottle is a struct that represents the result of CreateSpecThrottle, UpdateSpecThrottle and
    90  // ListSpecThrottles methods.
    91  type SpecThrottle struct {
    92  	// Maximum number of times the excluded object can access an API within the throttling period.
    93  	CallLimits int `json:"call_limits"`
    94  	// Name of the app to which the excluded request throttling configuration applies.
    95  	AppName string `json:"app_name"`
    96  	// Name of an app or a tenant to which the excluded request throttling configuration applies.
    97  	ObjectName string `json:"object_name"`
    98  	// ID of an object specified in the excluded request throttling configuration.
    99  	ObjectId string `json:"object_id"`
   100  	// Request throttling policy ID.
   101  	ThrottleId string `json:"throttle_id"`
   102  	// Time when the excluded request throttling configuration is created.
   103  	ApplyTime string `json:"apply_time"`
   104  	// Excluded request throttling configuration ID.
   105  	ID string `json:"id"`
   106  	// ID of the app to which the excluded request throttling configuration applies.
   107  	AppId string `json:"app_id"`
   108  	// Excluded object type, which can be APP or USER.
   109  	ObjectType string `json:"object_type"`
   110  }
   111  
   112  // The SpecThrottleResult represents the base result of the each special throttling polciy methods.
   113  type SpecThrottleResult struct {
   114  	commonResult
   115  }
   116  
   117  // The CreateSpecThrottleResult represents the result of the CreateSpecThrottle method.
   118  type CreateSpecThrottleResult struct {
   119  	SpecThrottleResult
   120  }
   121  
   122  // The UpdateSpecThrottleResult represents the result of the UpdateSpecThrottle method.
   123  type UpdateSpecThrottleResult struct {
   124  	SpecThrottleResult
   125  }
   126  
   127  // Extract is a method which to extract the response to a special throttling policy.
   128  func (r SpecThrottleResult) Extract() (*SpecThrottle, error) {
   129  	var s SpecThrottle
   130  	err := r.ExtractInto(&s)
   131  	return &s, err
   132  }
   133  
   134  // The SpecThrottlePage represents the result of a List operation.
   135  type SpecThrottlePage struct {
   136  	pagination.SinglePageBase
   137  }
   138  
   139  // ExtractSpecThrottles its Extract method to interpret it as a special throttling policy array.
   140  func ExtractSpecThrottles(r pagination.Page) ([]SpecThrottle, error) {
   141  	var s []SpecThrottle
   142  	err := r.(SpecThrottlePage).Result.ExtractIntoSlicePtr(&s, "throttle_specials")
   143  	return s, err
   144  }