router

package
v0.2.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2018 License: Apache-2.0 Imports: 17 Imported by: 11

Documentation

Index

Constants

View Source
const MuxPathRegex = ".+"

Variables

View Source
var ErrNoEventsFound = errors.New("no events with type 'Api' were found")

ErrNoEventsFound is thrown if a AWS::Serverless::Function is added to this router, but no API event sources exist for it.

View Source
var HttpMethods = []string{"OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "PATCH"}

Functions

This section is empty.

Types

type AWSServerlessApi

type AWSServerlessApi struct {
	*cloudformation.AWSServerlessApi
}

AWSServerlessApi wraps GoFormation's AWS::Serverless::Api definition and adds some convenience methods for extracting the ServerlessRouterMount's from the swagger defintion etc.

func (*AWSServerlessApi) Mounts

func (api *AWSServerlessApi) Mounts() ([]*ServerlessRouterMount, error)

Mounts fetches an array of the ServerlessRouterMount's for this API. These contain the path, method and handler function for each mount point.

func (*AWSServerlessApi) Swagger

func (api *AWSServerlessApi) Swagger() ([]byte, error)

Swagger gets the swagger definition for the API. Returns the swagger definition as a []byte of JSON.

type AWSServerlessFunction

type AWSServerlessFunction struct {
	*cloudformation.AWSServerlessFunction
	// contains filtered or unexported fields
}

AWSServerlessFunction wraps GoFormation's AWS::Serverless::Function definition and adds some convenience methods for extracting the ServerlessRouterMount's from the event sources.

func (*AWSServerlessFunction) Mounts

Mounts fetches an array of the ServerlessRouterMount's for this API. These contain the path, method and handler function for each mount point.

type ApiGatewayAnyMethod added in v0.2.3

type ApiGatewayAnyMethod struct {
	IntegrationSettings interface{} `json:"x-amazon-apigateway-integration"`
}

temporary object. This is just used to marshal and unmarshal the any method API Gateway swagger extension

type ApiGatewayIntegration added in v0.2.3

type ApiGatewayIntegration struct {
	Uri                 string `json:"uri"`
	PassthroughBehavior string `json:"passthroughBehavior"`
	Type                string `json:"type"`
}

func (*ApiGatewayIntegration) GetFunctionArn added in v0.2.3

func (i *ApiGatewayIntegration) GetFunctionArn() (*LambdaFunctionArn, error)

type ContextIdentity added in v0.2.7

type ContextIdentity struct {
	APIKey                        string `json:"apiKey,omitempty"`
	UserARN                       string `json:"userArn,omitempty"`
	CognitoAuthenticationType     string `json:"cognitoAuthenticationType,omitempty"`
	Caller                        string `json:"caller,omitempty"`
	UserAgent                     string `json:"userAgent,omitempty"`
	User                          string `json:"user,omitempty"`
	CognitoIdentityPoolID         string `json:"cognitoIdentityPoolId,omitempty"`
	CognitoIdentityID             string `json:"cognitoIdentityId,omitempty"`
	CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider,omitempty"`
	SourceIP                      string `json:"sourceIp,omitempty"`
	AccountID                     string `json:"accountId,omitempty"`
}

ContextIdentity represents the identity section of the context object that gets passed to an AWS Lambda function

type Event added in v0.2.7

type Event struct {
	HTTPMethod        string            `json:"httpMethod"`
	Body              string            `json:"body"`
	Resource          string            `json:"resource"`
	RequestContext    RequestContext    `json:"requestContext"`
	QueryStringParams map[string]string `json:"queryStringParameters"`
	Headers           map[string]string `json:"headers"`
	PathParameters    map[string]string `json:"pathParameters"`
	StageVariables    map[string]string `json:"stageVariables"`
	Path              string            `json:"path"`
	IsBase64Encoded   bool              `json:"isBase64Encoded"`
}

Event represents an event passed to an AWS Lambda function by the runtime

func NewEvent added in v0.2.7

func NewEvent(req *http.Request, isBase64Encoded bool) (*Event, error)

NewEvent initalises and populates a new ApiEvent with event details from a http.Request and isBase64Encoded value

func (*Event) JSON added in v0.2.7

func (e *Event) JSON() (string, error)

JSON returns the event as a JSON string

type EventHandlerFunc added in v0.2.7

type EventHandlerFunc func(http.ResponseWriter, *Event)

EventHandlerFunc is similar to Go http.Handler but it receives an event from API Gateway instead of http.Request

type LambdaFunctionArn added in v0.2.3

type LambdaFunctionArn struct {
	Arn string
}

func (*LambdaFunctionArn) GetFunctionName added in v0.2.3

func (a *LambdaFunctionArn) GetFunctionName() (string, error)

type RequestContext added in v0.2.7

type RequestContext struct {
	ResourceID   string          `json:"resourceId,omitempty"`
	APIID        string          `json:"apiId,omitempty"`
	ResourcePath string          `json:"resourcePath,omitempty"`
	HTTPMethod   string          `json:"httpMethod,omitempty"`
	RequestID    string          `json:"requestId,omitempty"`
	AccountsID   string          `json:"accountId,omitempty"`
	Stage        string          `json:"stage,omitempty"`
	Identity     ContextIdentity `json:"identity,omitempty"`
}

RequestContext represents the context object that gets passed to an AWS Lambda function

type ServerlessRouter

type ServerlessRouter struct {
	// contains filtered or unexported fields
}

ServerlessRouter takes AWS::Serverless::Function and AWS::Serverless::API objects and creates a Go http.Handler with the correct paths/methods mounted

func NewServerlessRouter

func NewServerlessRouter(usePrefix bool) *ServerlessRouter

NewServerlessRouter creates a new instance of ServerlessRouter. If usePrefix is true then route matching is done using prefix instead of exact match

func (*ServerlessRouter) AddAPI

AddAPI adds a AWS::Serverless::Api resource to the router, and mounts all of it's API definition

func (*ServerlessRouter) AddFunction

AddFunction adds a AWS::Serverless::Function to the router and mounts all of it's event sources that have type 'Api'

func (*ServerlessRouter) AddStaticDir

func (r *ServerlessRouter) AddStaticDir(dirname string)

AddStaticDir mounts a static directory provided, at the mount point also provided

func (*ServerlessRouter) Mounts

func (r *ServerlessRouter) Mounts() []*ServerlessRouterMount

Mounts returns a list of the mounts associated with this router

func (*ServerlessRouter) Router

func (r *ServerlessRouter) Router() http.Handler

Router returns the Go http.Handler for the router, to be passed to http.ListenAndServe()

type ServerlessRouterMount

type ServerlessRouterMount struct {
	Name             string
	Function         *AWSServerlessFunction
	Handler          EventHandlerFunc
	Path             string
	Method           string
	BinaryMediaTypes []string

	// authorization settings
	AuthType       string
	AuthFunction   *AWSServerlessFunction
	IntegrationArn *LambdaFunctionArn
}

ServerlessRouterMount represents a single mount point on the API Such as '/path', the HTTP method, and the function to resolve it

func (*ServerlessRouterMount) GetMuxPath added in v0.2.3

func (m *ServerlessRouterMount) GetMuxPath() string

Returns the mount path adjusted for mux syntax. For example, if the SAM template specifies /{proxy+} we replace that with /{proxy:.*}

func (*ServerlessRouterMount) Methods

func (m *ServerlessRouterMount) Methods() []string

Methods gets an array of HTTP methods from a AWS::Serverless::Function API event source method declaration (which could include 'any')

func (*ServerlessRouterMount) WrappedHandler added in v0.2.7

func (m *ServerlessRouterMount) WrappedHandler() http.HandlerFunc

Returns the wrapped handler to encode the body as base64 when binary media types contains Content-Type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL