/
dictionary_info.go
57 lines (45 loc) · 1.42 KB
/
dictionary_info.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
package fastly
import (
"fmt"
"time"
)
// DictionaryInfo represents a dictionary metadata response from the Fastly API.
type DictionaryInfo struct {
// LastUpdated is the Time-stamp (GMT) when the dictionary was last updated.
LastUpdated *time.Time `mapstructure:"last_updated"`
// Digest is the hash of the dictionary content.
Digest string `mapstructure:"digest"`
// ItemCount is the number of items belonging to the dictionary.
ItemCount int `mapstructure:"item_count"`
}
// GetDictionaryInfoInput is used as input to the GetDictionary function.
type GetDictionaryInfoInput struct {
// ServiceID is the ID of the service Dictionary belongs to (required).
ServiceID string
// Version is the specific configuration version (required).
Version int
// ID is the alphanumeric string identifying a dictionary.
ID string
}
// GetDictionaryInfo gets the dictionary metadata with the given parameters.
func (c *Client) GetDictionaryInfo(i *GetDictionaryInfoInput) (*DictionaryInfo, error) {
if i.ServiceID == "" {
return nil, ErrMissingService
}
if i.Version == 0 {
return nil, ErrMissingVersion
}
if i.ID == "" {
return nil, ErrMissingID
}
path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s/info", i.ServiceID, i.Version, i.ID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
var b *DictionaryInfo
if err := decodeBodyMap(resp.Body, &b); err != nil {
return nil, err
}
return b, nil
}