-
Notifications
You must be signed in to change notification settings - Fork 31
/
cache_setting.go
51 lines (43 loc) · 1.5 KB
/
cache_setting.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
package edge_applications
import (
"context"
"github.com/aziontech/azion-cli/pkg/logger"
"github.com/aziontech/azion-cli/utils"
"go.uber.org/zap"
)
// CreateCacheSettingsNextApplication this function creates the necessary Cache Settings for next applications
// to work correctly on the edge
func (c *Client) CreateCacheSettingsNextApplication(
ctx context.Context, req *CreateCacheSettingsRequest,
applicationID int64,
) (CacheSettingsResponse, error) {
logger.Debug("Create Cache Settings Next Application")
req.SetBrowserCacheSettings("override")
req.SetBrowserCacheSettingsMaximumTtl(7200)
req.SetCdnCacheSettings("override")
req.SetCdnCacheSettingsMaximumTtl(7200)
resp, err := c.CreateCacheEdgeApplication(ctx, req, applicationID)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *Client) CreateCacheEdgeApplication(
ctx context.Context, req *CreateCacheSettingsRequest, edgeApplicationID int64,
) (CacheSettingsResponse, error) {
logger.Debug("Create Cache Edge Application")
resp, httpResp, err := c.apiClient.EdgeApplicationsCacheSettingsAPI.
EdgeApplicationsEdgeApplicationIdCacheSettingsPost(ctx, edgeApplicationID).
ApplicationCacheCreateRequest(req.ApplicationCacheCreateRequest).Execute()
if err != nil {
if httpResp != nil {
logger.Debug("Error while creating a cache setting", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return nil, err
}
}
return nil, utils.ErrorPerStatusCode(httpResp, err)
}
return resp.Results, nil
}