github.com/fastly/go-fastly@v1.18.0/fastly/fastly.go (about)

     1  package fastly
     2  
     3  import (
     4  	"bytes"
     5  	"encoding"
     6  )
     7  
     8  type BatchOperation string
     9  
    10  const (
    11  	CreateBatchOperation BatchOperation = "create"
    12  	UpdateBatchOperation BatchOperation = "update"
    13  	UpsertBatchOperation BatchOperation = "upsert"
    14  	DeleteBatchOperation BatchOperation = "delete"
    15  
    16  	// Represents the maximum number of operations that can be sent within a single batch request.
    17  	// This is currently not documented in the API.
    18  	BatchModifyMaximumOperations = 1000
    19  
    20  	// Represents the maximum number of items that can be placed within an Edge Dictionary.
    21  	MaximumDictionarySize = 10000
    22  
    23  	// Represents the maximum number of entries that can be placed within an ACL.
    24  	MaximumACLSize = 10000
    25  )
    26  
    27  type statusResp struct {
    28  	Status string
    29  	Msg    string
    30  }
    31  
    32  func (t *statusResp) Ok() bool {
    33  	return t.Status == "ok"
    34  }
    35  
    36  // Ensure Compatibool implements the proper interfaces.
    37  var (
    38  	_ encoding.TextMarshaler   = new(Compatibool)
    39  	_ encoding.TextUnmarshaler = new(Compatibool)
    40  )
    41  
    42  // Helper function to get a pointer to bool
    43  func CBool(b bool) *Compatibool {
    44  	c := Compatibool(b)
    45  	return &c
    46  }
    47  
    48  // Compatibool is a boolean value that marshalls to 0/1 instead of true/false
    49  // for compatibility with Fastly's API.
    50  type Compatibool bool
    51  
    52  // MarshalText implements the encoding.TextMarshaler interface.
    53  func (b Compatibool) MarshalText() ([]byte, error) {
    54  	if b {
    55  		return []byte("1"), nil
    56  	}
    57  	return []byte("0"), nil
    58  }
    59  
    60  // UnmarshalText implements the encoding.TextUnmarshaler interface.
    61  func (b *Compatibool) UnmarshalText(t []byte) error {
    62  	if bytes.Equal(t, []byte("1")) {
    63  		*b = Compatibool(true)
    64  	}
    65  	return nil
    66  }
    67  
    68  // String is a helper that returns a pointer to the string value passed in.
    69  func String(v string) *string {
    70  	return &v
    71  }
    72  
    73  // NullString is a helper that returns a pointer to the string value passed in
    74  // or nil if the string is empty.
    75  func NullString(v string) *string {
    76  	if v == "" {
    77  		return nil
    78  	}
    79  	return &v
    80  }
    81  
    82  // Uint is a helper that returns a pointer to the uint value passed in.
    83  func Uint(v uint) *uint {
    84  	return &v
    85  }
    86  
    87  // Bool is a helper that returns a pointer to the bool value passed in.
    88  func Bool(v bool) *bool {
    89  	return &v
    90  }