Debian Codegraph @

fastly/diff.go

raw symbols SCIP
1 package fastly
2
3 import "fmt"
4
5 // Diff represents a diff of two versions as a response from the Fastly API.
6 type Diff struct {
7 Format string `mapstructure:"format"`
8 From int `mapstructure:"from"`
9 To int `mapstructure:"to"`
10 Diff string `mapstructure:"diff"`
11 }
12
13 // GetDiffInput is used as input to the GetDiff function.
14 type GetDiffInput struct {
15 // Service is the ID of the service (required).
16 Service string
17
18 // From is the version to diff from. This can either be a string indicating a
19 // positive number (e.g. "1") or a negative number from "-1" down ("-1" is the
20 // latest version).
21 From int
22
23 // To is the version to diff up to. The same rules for From apply.
24 To int
25
26 // Format is an optional field to specify the format with which the diff will
27 // be returned. Acceptable values are "text" (default), "html", or
28 // "html_simple".
29 Format string
30 }
31
32 // GetDiff returns the diff of the given versions.
33 func (c *Client) GetDiff(i *GetDiffInput) (*Diff, error) {
34 if i.Service == "" {
35 return nil, ErrMissingService
36 }
37
38 if i.From == 0 {
39 return nil, ErrMissingFrom
40 }
41
42 if i.To == 0 {
43 return nil, ErrMissingTo
44 }
45
46 path := fmt.Sprintf("service/%s/diff/from/%d/to/%d", i.Service, i.From, i.To)
47 resp, err := c.Get(path, nil)
48 if err != nil {
49 return nil, err
50 }
51
52 var d *Diff
53 if err := decodeJSON(&d, resp.Body); err != nil {
54 return nil, err
55 }
56 return d, nil
57 }