-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontier.go
54 lines (47 loc) · 1.09 KB
/
frontier.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
package frontier
import (
"os"
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
"github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
)
type Function struct {
Name string
Code *FunctionCode
Config *FunctionConfig
}
type FunctionCode struct {
Path string
}
func (f *Function) toCreateInput() (*cloudfront.CreateFunctionInput, error) {
body, err := os.ReadFile(f.Code.Path)
if err != nil {
return nil, err
}
return &cloudfront.CreateFunctionInput{
Name: &f.Name,
FunctionCode: body,
FunctionConfig: &types.FunctionConfig{
Comment: &f.Config.Comment,
Runtime: f.Config.Runtime,
},
}, nil
}
func (fn *Function) toUpdateInput(etag *string) (*cloudfront.UpdateFunctionInput, error) {
body, err := os.ReadFile(fn.Code.Path)
if err != nil {
return nil, err
}
return &cloudfront.UpdateFunctionInput{
Name: &fn.Name,
FunctionCode: body,
IfMatch: etag,
FunctionConfig: &types.FunctionConfig{
Comment: &fn.Config.Comment,
Runtime: fn.Config.Runtime,
},
}, nil
}
type FunctionConfig struct {
Comment string
Runtime types.FunctionRuntime
}