-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (49 loc) · 1.65 KB
/
main.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
55
56
57
58
59
60
61
package main
import (
"context"
"github.com/alecthomas/kong"
"github.com/apex/gateway"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
lmw "github.com/wolfeidau/lambda-go-extras/middleware"
"github.com/wolfeidau/lambda-go-extras/middleware/raw"
zlog "github.com/wolfeidau/lambda-go-extras/middleware/zerolog"
"github.com/wolfeidau/lambda-golang-containers/internal/server"
)
var (
version = "unknown"
cli struct {
Version kong.VersionFlag
RawEventLogging bool `help:"Enable raw event logging." env:"RAW_EVENT_LOGGING"`
Debug bool `help:"Enable debug logging." env:"DEBUG"`
Stage string `help:"The development stage." env:"STAGE"`
Branch string `help:"The git branch this code originated." env:"BRANCH"`
}
)
func main() {
kong.Parse(&cli,
kong.Vars{"version": version}, // bind a var for version
)
// build up a list of fields which will be included in all log messages
flds := lmw.FieldMap{"version": version}
ch := lmw.New(
zlog.New(zlog.Fields(flds)), // assign a logger and bind it in the context
)
if cli.RawEventLogging {
ch.Use(raw.New(raw.Fields(flds))) // if raw event logging is enabled dump everything to the log in and out
}
awscfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.Fatal().Err(err).Msg("unable to load SDK config")
}
e := echo.New()
err = server.Setup(awscfg, e)
if err != nil {
log.Fatal().Err(err).Msg("server setup failed")
}
gw := gateway.NewGateway(e)
// register our lambda handler with the middleware configured
lambda.StartHandler(ch.Then(gw))
}