forked from fastly/go-fastly
/
dictionary_info.go
52 lines (46 loc) · 1.46 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
package fastly
import (
"fmt"
"time"
)
// DictionaryInfo represents a dictionary metadata response from the Fastly API.
type DictionaryInfo struct {
// 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"`
// LastUpdated is the Time-stamp (GMT) when the dictionary was last updated.
LastUpdated *time.Time `mapstructure:"last_updated"`
}
// GetDictionaryInfoInput is used as input to the GetDictionary function.
type GetDictionaryInfoInput struct {
// ID is the alphanumeric string identifying a dictionary (required).
ID string
// ServiceID is the ID of the service Dictionary belongs to (required).
ServiceID string
// ServiceVersion is the specific configuration version (required).
ServiceVersion int
}
// GetDictionaryInfo retrieves the specified resource.
func (c *Client) GetDictionaryInfo(i *GetDictionaryInfoInput) (*DictionaryInfo, error) {
if i.ID == "" {
return nil, ErrMissingID
}
if i.ServiceID == "" {
return nil, ErrMissingServiceID
}
if i.ServiceVersion == 0 {
return nil, ErrMissingServiceVersion
}
path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s/info", i.ServiceID, i.ServiceVersion, i.ID)
resp, err := c.Get(path, nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var b *DictionaryInfo
if err := decodeBodyMap(resp.Body, &b); err != nil {
return nil, err
}
return b, nil
}