github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/apigw/v2/tr_specials/Create.go (about)

     1  package special_policy
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type CreateOpts struct {
    10  	GatewayID  string `json:"-"`
    11  	ThrottleID string `json:"throttle_id" required:"true"`
    12  	CallLimits int    `json:"call_limits" required:"true"`
    13  	ObjectID   string `json:"object_id" required:"true"`
    14  	ObjectType string `json:"object_type" required:"true"`
    15  }
    16  
    17  func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*ThrottlingResp, error) {
    18  	b, err := build.RequestBody(opts, "")
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  
    23  	raw, err := client.Post(client.ServiceURL("apigw", "instances", opts.GatewayID, "throttles",
    24  		opts.ThrottleID, "throttle-specials"), b, nil, &golangsdk.RequestOpts{
    25  		OkCodes: []int{201},
    26  	})
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  
    31  	var res ThrottlingResp
    32  
    33  	err = extract.Into(raw.Body, &res)
    34  	return &res, err
    35  }
    36  
    37  type ThrottlingResp struct {
    38  	ID         string `json:"id"`
    39  	CallLimits int    `json:"call_limits"`
    40  	ApplyTime  string `json:"apply_time"`
    41  	AppName    string `json:"app_name"`
    42  	AppID      string `json:"app_id"`
    43  	ObjectID   string `json:"object_id"`
    44  	ObjectType string `json:"object_type"`
    45  	ObjectName string `json:"object_name"`
    46  	ThrottleID string `json:"throttle_id"`
    47  }