• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fogfish / scud / 10864418864

14 Sep 2024 05:59PM UTC coverage: 92.857% (-0.5%) from 93.377%
10864418864

push

github

web-flow
(fea) universal function interface (#27)

* (fea) universal function interface

6 of 9 new or added lines in 3 files covered. (66.67%)

429 of 462 relevant lines covered (92.86%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.14
/handler.go
1
//
2
// Copyright (C) 2020 - 2024 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license.  See the LICENSE file for details.
6
// https://github.com/fogfish/scud
7
//
8

9
package scud
10

11
import (
12
        "fmt"
13
        "path/filepath"
14

15
        "github.com/aws/aws-cdk-go/awscdk/v2"
16
        "github.com/aws/aws-cdk-go/awscdk/v2/awslambda"
17
        "github.com/aws/aws-cdk-go/awscdk/v2/awslogs"
18
        "github.com/aws/constructs-go/constructs/v10"
19
        "github.com/aws/jsii-runtime-go"
20
)
21

22
// FunctionGoProps is properties of the function
23
type FunctionGoProps struct {
24
        *awslambda.FunctionProps
25

26
        // Canonical name of Golang module that containing the function
27
        //        SourceCodeModule: "github.com/fogfish/scud",
28
        SourceCodeModule string
29

30
        // Path to lambda function relative to the module
31
        //        SourceCodeLambda:  "test/lambda/go"
32
        SourceCodeLambda string
33

34
        // The version of software asset passed as linker flag
35
        //        -ldflags '-X main.version=...'
36
        SourceCodeVersion string
37

38
        // Variables and its values passed as linker flags
39
        //        -ldflags '-X key1=val1 -X key2=val2 ...'
40
        GoVar map[string]string
41

42
        // Go environment, default includes
43
        //        GOOS=linux
44
        //        GOARCH=arm64
45
        //        CGO_ENABLED=0
46
        GoEnv map[string]string
47
}
48

NEW
49
func (*FunctionGoProps) Type(awslambda.Function) {}
×
50

51
// NewFunctionGo creates Golang Lambda Function from "inline" code
52
func NewFunctionGo(scope constructs.Construct, id *string, spec *FunctionGoProps) awslambda.Function {
1✔
53
        var props awslambda.FunctionProps
1✔
54
        if spec.FunctionProps != nil {
2✔
55
                props = *spec.FunctionProps
1✔
56
        }
1✔
57

58
        if props.Timeout == nil {
2✔
59
                props.Timeout = awscdk.Duration_Minutes(jsii.Number(1))
1✔
60
        }
1✔
61

62
        if props.LogRetention == "" {
2✔
63
                props.LogRetention = awslogs.RetentionDays_FIVE_DAYS
1✔
64
        }
1✔
65

66
        if props.FunctionName == nil {
2✔
67
                props.FunctionName = jsii.String(fmt.Sprintf("%s-%s",
1✔
68
                        *awscdk.Aws_STACK_NAME(), filepath.Base(filepath.Join(spec.SourceCodeModule, spec.SourceCodeLambda))))
1✔
69
        }
1✔
70

71
        // arm64 is default deployment
72
        props.Architecture = awslambda.Architecture_ARM_64()
1✔
73
        if spec.GoEnv != nil {
2✔
74
                switch spec.GoEnv["GOARCH"] {
1✔
75
                case "amd64":
1✔
76
                        props.Architecture = awslambda.Architecture_X86_64()
1✔
77
                case "arm64":
1✔
78
                        props.Architecture = awslambda.Architecture_ARM_64()
1✔
79
                }
80
        }
81

82
        gocc := NewGoCompiler(
1✔
83
                spec.SourceCodeModule,
1✔
84
                spec.SourceCodeLambda,
1✔
85
                spec.SourceCodeVersion,
1✔
86
                spec.GoVar,
1✔
87
                spec.GoEnv,
1✔
88
        )
1✔
89
        props.Code = AssetCodeGo(gocc)
1✔
90
        props.Handler = jsii.String(goBinary)
1✔
91
        props.Runtime = awslambda.Runtime_PROVIDED_AL2()
1✔
92

1✔
93
        return awslambda.NewFunction(scope, id, &props)
1✔
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc