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

     1  package throttling_policy
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type BindOpts struct {
    10  	GatewayID  string   `json:"-"`
    11  	PolicyID   string   `json:"strategy_id" required:"true"`
    12  	PublishIds []string `json:"publish_ids" required:"true"`
    13  }
    14  
    15  func BindPolicy(client *golangsdk.ServiceClient, opts BindOpts) ([]BindThrottleResp, error) {
    16  	b, err := build.RequestBody(opts, "")
    17  	if err != nil {
    18  		return nil, err
    19  	}
    20  
    21  	raw, err := client.Post(client.ServiceURL("apigw", "instances", opts.GatewayID, "throttle-bindings"), b,
    22  		nil, &golangsdk.RequestOpts{
    23  			OkCodes: []int{201},
    24  		})
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  
    29  	var res []BindThrottleResp
    30  
    31  	err = extract.IntoSlicePtr(raw.Body, &res, "throttle_applys")
    32  	return res, err
    33  }
    34  
    35  type BindThrottleResp struct {
    36  	PublishID  string `json:"publish_id"`
    37  	Scope      int    `json:"scope"`
    38  	StrategyID string `json:"strategy_id"`
    39  	ApplyTime  string `json:"apply_time"`
    40  	ID         string `json:"id"`
    41  }