Closed podhmo closed 2 years ago
type DoInput struct{}
func Do(logger *log.Logger, data DoInput, debug *bool, targetID string) (interface{}, error) {
return nil, nil
}
generator code
c := g.Generate(pkg, action.Do, WithRenameField("targetID", "targetId"))
// generate main()
g.IncludePlugin(pkg, emitmain.Options{HandlerCode: c, GetProvider: "<code ?>"})
// generate init() and global variables (for state)
generated code
type DoEvent struct {
Data DoInput `json:"data"`
Debug *bool `json:"debug"`
TargetID string `json:"targetId"` // rename to targetId ? (in json)
}
type Provider interface {
Logger(ctx context.Context) (*log.Logger, error)
}
func DoHandler(getProvider func(ctx context.Context) (Provider, error)) func(ctx context.Context, event DoEvent) (interface{}, error) {
return func(ctx context.Context, event DoEvent) (interface{}, error) {
provider, err := getProvider(ctx)
if err != nil {
return nil, err // custom error handling?
}
var logger *log.Logger
{
var err error
logger, err = provider.Logger(ctx)
if err != nil {
return nil, err
}
}
return Do(logger, event.Data, event.Debug, event.TargetID)
}
}
func main() {
lambda.Start(DoHandler(getProvider))
}
If you want to get terraform code?, generate it, as you like (For example, create terraform module)
if func -> struct transformation automatically, cannot handle validation?
or something like below
g.Generate(pkg, action.Do, WithTag("targetId", `validate: regexp="^[a-f0-9]{24}"`))
or
type ObjectID string
func (id *ObjectId) TagString() string { return `<tag>` }
148, lambda handler is also not having path and query-string, so another handling way for the argument that treated as primitive and primitive-pointer is needed. this is same in the situation using cli.
memo