Skip to content

Commit

Permalink
feat: added a fire-once entrypoint template for the go-lambda template
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjydev committed May 9, 2024
1 parent 2ec29ea commit b5e5607
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
44 changes: 37 additions & 7 deletions internal/config/go_lambda.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package config

import (
"errors"
"fmt"
"os"

"github.com/ALT-F4-LLC/build-configs/internal/templates"
)

Expand All @@ -20,13 +24,14 @@ type GoLambdaConfig struct {

func NewGoLambdaConfig(c Config) GoLambdaConfig {
return GoLambdaConfig{
Config: c,
GoVersion: "1.22",
Lint: NewGolangCiLintConfig(),
Quirk: NewQuirkConfig(c),
Deploy: []DeployConfig{},
Lambdas: []string{c.Name},
OpenAPI: NewOpenAPIConfig(),
Config: c,
GoVersion: "1.22",
PrivateModules: "github.com/ALT-F4-LLC/quirk-service-kit",
Lint: NewGolangCiLintConfig(),
Quirk: NewQuirkConfig(c),
Deploy: []DeployConfig{},
Lambdas: []string{c.Name},
OpenAPI: NewOpenAPIConfig(),

Nix: NixGoConfig{
NixConfig: NewNixConfig(),
Expand Down Expand Up @@ -64,5 +69,30 @@ func (c GoLambdaConfig) Render() error {
return err
}

// Create lambda entrypoints on first template run
for _, lambda := range c.Lambdas {
entry := fmt.Sprintf("cmd/%s/main.go", lambda)

if _, err := os.Stat(entry); err != nil {
if errors.Is(err, os.ErrNotExist) {
out, err := templates.RenderTemplate(
templates.GoLambdaTemplates,
"cmd/[lambda]/main.go",
c,
)
if err != nil {
return err
}
files[entry] = out
} else {
// Error was unexpected
return err
}
} else {
// File exists
continue
}
}

return templates.WriteFiles(files)
}
31 changes: 31 additions & 0 deletions internal/templates/templates/go-lambda/cmd__[lambda]__main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"context"

"github.com/ALT-F4-LLC/quirk-service-kit/config"
"github.com/ALT-F4-LLC/quirk-service-kit/lambda"
"github.com/ALT-F4-LLC/quirk-service-kit/telemetry"
"github.com/ALT-F4-LLC/quirk-service-kit/aws"
"github.com/aws/aws-lambda-go/events"
)

type Config struct {
*config.BaseConfig
}

var cfg Config

func Handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) {
// l := telemetry.GetLogger(ctx)
// awsCfg := aws.GetConfig(ctx)
// env := cfg.BaseConfig.Environment

return lambda.NewOkResponse(), nil
}

func main() {
if err := lambda.Start(Handler, &Config{}); err != nil {
panic(err)
}
}

0 comments on commit b5e5607

Please sign in to comment.