-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcacheinvalidation.go
More file actions
117 lines (102 loc) · 4.19 KB
/
cacheinvalidation.go
File metadata and controls
117 lines (102 loc) · 4.19 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package imagekit
import (
"context"
"errors"
"fmt"
"net/http"
"slices"
"github.com/imagekit-developer/imagekit-go/v2/internal/apijson"
"github.com/imagekit-developer/imagekit-go/v2/internal/requestconfig"
"github.com/imagekit-developer/imagekit-go/v2/option"
"github.com/imagekit-developer/imagekit-go/v2/packages/param"
"github.com/imagekit-developer/imagekit-go/v2/packages/respjson"
)
// CacheInvalidationService contains methods and other services that help with
// interacting with the ImageKit API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewCacheInvalidationService] method instead.
type CacheInvalidationService struct {
Options []option.RequestOption
}
// NewCacheInvalidationService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewCacheInvalidationService(opts ...option.RequestOption) (r CacheInvalidationService) {
r = CacheInvalidationService{}
r.Options = opts
return
}
// This API will purge CDN cache and ImageKit.io's internal cache for a file. Note:
// Purge cache is an asynchronous process and it may take some time to reflect the
// changes.
func (r *CacheInvalidationService) New(ctx context.Context, body CacheInvalidationNewParams, opts ...option.RequestOption) (res *CacheInvalidationNewResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "v1/files/purge"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// This API returns the status of a purge cache request.
func (r *CacheInvalidationService) Get(ctx context.Context, requestID string, opts ...option.RequestOption) (res *CacheInvalidationGetResponse, err error) {
opts = slices.Concat(r.Options, opts)
if requestID == "" {
err = errors.New("missing required requestId parameter")
return nil, err
}
path := fmt.Sprintf("v1/files/purge/%s", requestID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
type CacheInvalidationNewResponse struct {
// Unique identifier of the purge request. This can be used to check the status of
// the purge request.
RequestID string `json:"requestId"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
RequestID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r CacheInvalidationNewResponse) RawJSON() string { return r.JSON.raw }
func (r *CacheInvalidationNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type CacheInvalidationGetResponse struct {
// Status of the purge request.
//
// Any of "Pending", "Completed".
Status CacheInvalidationGetResponseStatus `json:"status"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Status respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r CacheInvalidationGetResponse) RawJSON() string { return r.JSON.raw }
func (r *CacheInvalidationGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Status of the purge request.
type CacheInvalidationGetResponseStatus string
const (
CacheInvalidationGetResponseStatusPending CacheInvalidationGetResponseStatus = "Pending"
CacheInvalidationGetResponseStatusCompleted CacheInvalidationGetResponseStatus = "Completed"
)
type CacheInvalidationNewParams struct {
// The full URL of the file to be purged.
URL string `json:"url" api:"required" format:"uri"`
paramObj
}
func (r CacheInvalidationNewParams) MarshalJSON() (data []byte, err error) {
type shadow CacheInvalidationNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *CacheInvalidationNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}