-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
render.go
47 lines (43 loc) · 1.18 KB
/
render.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
package lambroll
import (
"context"
"fmt"
"os"
)
type RenderOption struct {
Jsonnet bool `default:"false" help:"render function.json as jsonnet"`
FunctionURL string `help:"render function-url definition file" default:"" env:"LAMBROLL_FUNCTION_URL"`
}
// Invoke invokes function
func (app *App) Render(ctx context.Context, opt *RenderOption) error {
fn, err := app.loadFunction(app.functionFilePath)
if err != nil {
return fmt.Errorf("failed to load function: %w", err)
}
var b []byte
if opt.FunctionURL != "" {
fu, err := app.loadFunctionUrl(opt.FunctionURL, *fn.FunctionName)
if err != nil {
return fmt.Errorf("failed to load function-url: %w", err)
}
b, err = marshalJSON(fu)
if err != nil {
return fmt.Errorf("failed to marshal function-url: %w", err)
}
} else {
b, err = marshalJSON(fn)
if err != nil {
return fmt.Errorf("failed to marshal function: %w", err)
}
}
if opt.Jsonnet {
b, err = jsonToJsonnet(b, app.functionFilePath)
if err != nil {
return fmt.Errorf("failed to render function.json as jsonnet: %w", err)
}
}
if _, err := os.Stdout.Write(b); err != nil {
return fmt.Errorf("failed to write function.json: %w", err)
}
return nil
}