// Code generated by 'cfn generate', changes will be undone by the next invocation. DO NOT EDIT. package main import ( "errors" "fmt" "log" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "{{ path }}" ) // Handler is a container for the CRUDL actions exported by resources type Handler struct{} {% for method in ("Create", "Read", "Update", "Delete", "List") %} // {{ method }} wraps the related {{ method }} function exposed by the resource code func (r *Handler) {{ method }}(req handler.Request) handler.ProgressEvent { return wrap(req, resource.{{ method }}) } {% endfor %} // main is the entry point of the application. func main() { cfn.Start(&Handler{}) } type handlerFunc func(handler.Request, *resource.Model, *resource.Model) (handler.ProgressEvent, error) func wrap(req handler.Request, f handlerFunc) (response handler.ProgressEvent) { defer func() { // Catch any panics and return a failed ProgressEvent if r := recover(); r != nil { err, ok := r.(error) if !ok { err = errors.New(fmt.Sprint(r)) } log.Printf("Trapped error in handler: %v", err) response = handler.NewFailedEvent(err) } }() // Populate the previous model prevModel := &resource.Model{} if err := req.UnmarshalPrevious(prevModel); err != nil { log.Printf("Error unmarshaling prev model: %v", err) return handler.NewFailedEvent(err) } // Populate the current model currentModel := &resource.Model{} if err := req.Unmarshal(currentModel); err != nil { log.Printf("Error unmarshaling model: %v", err) return handler.NewFailedEvent(err) } response, err := f(req, prevModel, currentModel) if err != nil { log.Printf("Error returned from handler function: %v", err) return handler.NewFailedEvent(err) } return response }