proxy

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package proxy provides API Gateway and Lambda interoperability.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(h http.Handler) apex.Handler

NewHandler returns an apex.Handler.

func NewRequest

func NewRequest(e *Input) (*http.Request, error)

NewRequest returns a new http.Request from the given Lambda event.

Types

type Identity

type Identity struct {
	APIKey                        string `json:"apiKey"`
	AccountID                     string `json:"accountId"`
	UserAgent                     string `json:"userAgent"`
	SourceIP                      string `json:"sourceIp"`
	AccessKey                     string `json:"accessKey"`
	Caller                        string `json:"caller"`
	User                          string `json:"user"`
	UserARN                       string `json:"userARN"`
	CognitoIdentityID             string `json:"cognitoIdentityId"`
	CognitoIdentityPoolID         string `json:"cognitoIdentityPoolId"`
	CognitoAuthenticationType     string `json:"cognitoAuthenticationType"`
	CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider"`
}

Identity is the identity information associated with the request.

type Input

type Input struct {
	HTTPMethod            string
	Headers               map[string]string
	Resource              string
	PathParameters        map[string]string
	Path                  string
	QueryStringParameters map[string]string
	Body                  string
	IsBase64Encoded       bool
	StageVariables        map[string]string
	RequestContext        RequestContext
}

Input is the input provided by API Gateway.

Example (Get)
var in Input
json.Unmarshal([]byte(getEvent), &in)
output(in)
Output:

{
  "HTTPMethod": "GET",
  "Headers": {
    "Accept": "*/*",
    "CloudFront-Forwarded-Proto": "https",
    "CloudFront-Is-Desktop-Viewer": "true",
    "CloudFront-Is-Mobile-Viewer": "false",
    "CloudFront-Is-SmartTV-Viewer": "false",
    "CloudFront-Is-Tablet-Viewer": "false",
    "CloudFront-Viewer-Country": "CA",
    "Host": "apex-ping.com",
    "User-Agent": "curl/7.48.0",
    "Via": "2.0 a44b4468444ef3ee67472bd5c5016098.cloudfront.net (CloudFront)",
    "X-Amz-Cf-Id": "VRxPGF8rOXD7xpRjAjseXfRrFD3wg-QPUHY6chzB9bR7pXlct1NTpg==",
    "X-Amzn-Trace-Id": "Root=1-59554c99-4375fc8705ccb554008b3aad",
    "X-Forwarded-For": "207.102.57.26, 54.182.214.69",
    "X-Forwarded-Port": "443",
    "X-Forwarded-Proto": "https"
  },
  "Resource": "/{proxy+}",
  "PathParameters": {
    "proxy": "pets/tobi"
  },
  "Path": "/pets/tobi",
  "QueryStringParameters": {
    "format": "json"
  },
  "Body": "",
  "IsBase64Encoded": false,
  "StageVariables": {
    "env": "prod"
  },
  "RequestContext": {
    "apiId": "iwcgwgigca",
    "resourceId": "jcl9w3",
    "requestId": "344b184b-5cfc-11e7-8483-27dbb2d30a77",
    "accountId": "111111111",
    "stage": "prod",
    "identity": {
      "apiKey": "",
      "accountId": "",
      "userAgent": "curl/7.48.0",
      "sourceIp": "207.102.57.26",
      "accessKey": "",
      "caller": "",
      "user": "",
      "userARN": "",
      "cognitoIdentityId": "",
      "cognitoIdentityPoolId": "",
      "cognitoAuthenticationType": "",
      "cognitoAuthenticationProvider": ""
    },
    "authorizer": null
  }
}
Example (Post)
var in Input
json.Unmarshal([]byte(postEvent), &in)
output(in)
Output:

{
  "HTTPMethod": "POST",
  "Headers": {
    "Accept": "*/*",
    "CloudFront-Forwarded-Proto": "https",
    "CloudFront-Is-Desktop-Viewer": "true",
    "CloudFront-Is-Mobile-Viewer": "false",
    "CloudFront-Is-SmartTV-Viewer": "false",
    "CloudFront-Is-Tablet-Viewer": "false",
    "CloudFront-Viewer-Country": "CA",
    "Host": "apex-ping.com",
    "User-Agent": "curl/7.48.0",
    "Via": "2.0 b790a9f06b09414fec5d8b87e81d4b7f.cloudfront.net (CloudFront)",
    "X-Amz-Cf-Id": "_h1jFD3wjq6ZIyr8be6RS7Y7665jF9SjACmVodBMRefoQCs7KwTxMw==",
    "X-Amzn-Trace-Id": "Root=1-59554cc9-35de2f970f0fdf017f16927f",
    "X-Forwarded-For": "207.102.57.26, 54.182.214.86",
    "X-Forwarded-Port": "443",
    "X-Forwarded-Proto": "https",
    "content-type": "application/json"
  },
  "Resource": "/{proxy+}",
  "PathParameters": {
    "proxy": "pets/tobi"
  },
  "Path": "/pets/tobi",
  "QueryStringParameters": null,
  "Body": "{ \"name\": \"Tobi\" }",
  "IsBase64Encoded": false,
  "StageVariables": null,
  "RequestContext": {
    "apiId": "iwcgwgigca",
    "resourceId": "jcl9w3",
    "requestId": "50f6e0ce-5cfc-11e7-ada1-4f5cfe727f01",
    "accountId": "111111111",
    "stage": "prod",
    "identity": {
      "apiKey": "",
      "accountId": "",
      "userAgent": "curl/7.48.0",
      "sourceIp": "207.102.57.26",
      "accessKey": "",
      "caller": "",
      "user": "",
      "userARN": "",
      "cognitoIdentityId": "",
      "cognitoIdentityPoolId": "",
      "cognitoAuthenticationType": "",
      "cognitoAuthenticationProvider": ""
    },
    "authorizer": null
  }
}

type Output

type Output struct {
	StatusCode      int               `json:"statusCode"`
	Headers         map[string]string `json:"headers,omitempty"`
	Body            string            `json:"body,omitempty"`
	IsBase64Encoded bool              `json:"isBase64Encoded"`
}

Output is the output expected by API Gateway.

type RequestContext

type RequestContext struct {
	APIID        string                 `json:"apiId"`
	ResourceID   string                 `json:"resourceId"`
	RequestID    string                 `json:"requestId"`
	HTTPMethod   string                 `json:"-"`
	ResourcePath string                 `json:"-"`
	AccountID    string                 `json:"accountId"`
	Stage        string                 `json:"stage"`
	Identity     Identity               `json:"identity"`
	Authorizer   map[string]interface{} `json:"authorizer"`
}

RequestContext is the contextual information provided by API Gateway.

type ResponseWriter

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

ResponseWriter implements the http.ResponseWriter interface in order to support the API Gateway Lambda HTTP "protocol".

func NewResponse

func NewResponse() *ResponseWriter

NewResponse returns a new response writer to capture http output.

func (*ResponseWriter) End

func (w *ResponseWriter) End() Output

End the request.

func (*ResponseWriter) Header

func (w *ResponseWriter) Header() http.Header

Header implementation.

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(b []byte) (int, error)

Write implementation.

func (*ResponseWriter) WriteHeader

func (w *ResponseWriter) WriteHeader(status int)

WriteHeader implementation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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