forked from fastly/go-fastly
/
fastly.go
79 lines (66 loc) · 2.03 KB
/
fastly.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package fastly
import (
"bytes"
"encoding"
"net/url"
)
// BatchOperation represents batching variants.
type BatchOperation string
const (
// CreateBatchOperation represents a batching variant.
CreateBatchOperation BatchOperation = "create"
// UpdateBatchOperation represents a batching variant.
UpdateBatchOperation BatchOperation = "update"
// UpsertBatchOperation represents a batching variant.
UpsertBatchOperation BatchOperation = "upsert"
// DeleteBatchOperation represents a batching variant.
DeleteBatchOperation BatchOperation = "delete"
// BatchModifyMaximumOperations represents the maximum number of operations
// that can be sent within a single batch request. This is currently not
// documented in the API.
BatchModifyMaximumOperations = 1000
// MaximumDictionarySize represents the maximum number of items that can be
// placed within an Edge Dictionary.
MaximumDictionarySize = 10000
// MaximumACLSize represents the maximum number of entries that can be placed
// within an ACL.
MaximumACLSize = 10000
)
type statusResp struct {
Msg string
Status string
}
func (t *statusResp) Ok() bool {
return t.Status == "ok"
}
// Ensure Compatibool implements the proper interfaces.
var (
_ encoding.TextMarshaler = new(Compatibool)
_ encoding.TextUnmarshaler = new(Compatibool)
)
// Compatibool is a boolean value that marshalls to 0/1 instead of true/false
// for compatibility with Fastly's API.
type Compatibool bool
// MarshalText implements the encoding.TextMarshaler interface.
func (b Compatibool) MarshalText() ([]byte, error) {
if b {
return []byte("1"), nil
}
return []byte("0"), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (b *Compatibool) UnmarshalText(t []byte) error {
if bytes.Equal(t, []byte("1")) {
*b = Compatibool(true)
}
return nil
}
// EncodeValues implements github.com/google/go-querystring/query#Encoder interface.
func (b Compatibool) EncodeValues(key string, v *url.Values) error {
if b {
v.Add(key, "1")
return nil
}
v.Add(key, "0")
return nil
}