/
function.go
37 lines (30 loc) · 1 KB
/
function.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
package router
import (
"github.com/awslabs/goformation/cloudformation"
)
// AWSServerlessFunction wraps GoFormation's AWS::Serverless::Function definition
// and adds some convenience methods for extracting the ServerlessRouterMount's
// from the event sources.
type AWSServerlessFunction struct {
*cloudformation.AWSServerlessFunction
handler EventHandlerFunc
}
// Mounts fetches an array of the ServerlessRouterMount's for this API.
// These contain the path, method and handler function for each mount point.
func (f *AWSServerlessFunction) Mounts() ([]*ServerlessRouterMount, error) {
mounts := []*ServerlessRouterMount{}
for name, event := range f.Events {
if event.Type == "Api" {
if event.Properties != nil && event.Properties.ApiEvent != nil {
mounts = append(mounts, &ServerlessRouterMount{
Name: name,
Path: event.Properties.ApiEvent.Path,
Method: event.Properties.ApiEvent.Method,
Handler: f.handler,
Function: f,
})
}
}
}
return mounts, nil
}