pullzone_edgerule_set_enabled.go raw

   1  package bunny
   2  
   3  import (
   4  	"context"
   5  	"fmt"
   6  )
   7  
   8  // SetEdgeRuleEnabledOptions represents the message that is sent to Add/Update Edge Rule endpoint.
   9  //
  10  // Bunny.net API docs: https://docs.bunny.net/reference/pullzonepublic_addedgerule
  11  type SetEdgeRuleEnabledOptions struct {
  12  	// ID must be set to the PullZone ID for that the EdgeRule should be enabled.
  13  	ID    *int64 `json:"Id,omitempty"`
  14  	Value *bool  `json:"Value,omitempty"`
  15  }
  16  
  17  // SetEdgeRuleEnabled enables or disables an Edge Rule of a Pull Zone.
  18  // The edgeRuleGUID field is called edgeRuleID in the API message and
  19  // documentation. It is the same then the GUID field in the EdgeRule message.
  20  //
  21  // Bunny.net API docs: https://docs.bunny.net/reference/pullzonepublic_addedgerule
  22  func (s *PullZoneService) SetEdgeRuleEnabled(ctx context.Context, pullZoneID int64, edgeRuleGUID string, opts *SetEdgeRuleEnabledOptions) error {
  23  	if opts != nil {
  24  		if opts.ID == nil {
  25  			s.client.logf("SetEdgeRuleEnabled: ID field is unset in SetEdgeRuleEnabledOptions")
  26  		} else if *opts.ID != pullZoneID {
  27  			s.client.logf("SetEdgeRuleEnabled: mismatched pullZoneID %d and SetEdgeRuleEnabledOptions.ID %d were passed, values should be equal", pullZoneID, *opts.ID)
  28  		}
  29  	}
  30  
  31  	path := fmt.Sprintf("pullzone/%d/edgerules/%s/setEdgeRuleEnabled", pullZoneID, edgeRuleGUID)
  32  
  33  	return resourcePost(ctx, s.client, path, opts)
  34  }
  35