router

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

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 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 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  http.HandlerFunc
	Path     string
	Method   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')

Jump to

Keyboard shortcuts

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