apig

package module
v0.0.0-...-cb5641d Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

README

apigateway

Add functionality around apex to make it easier to build and deploy apis written in go to AWS serverless infrastructure

Documentation

Index

Constants

View Source
const SET_COOKIE = "setcookie"

Variables

View Source
var ErrNoHandler = errors.New("No handler defined for event of that type")

Functions

func LambdaHandler

func LambdaHandler(handler http.Handler, fallback lambdaHandlerFunc) lambdaHandlerFunc

LambdaHandler ...

func Respond

func Respond(body interface{}, status int, req events.APIGatewayProxyRequest, err error) (events.APIGatewayProxyResponse, error)

Respond will produce a response that will get formatted such that apigateway will modify it's response to the browser

func RespondHTTP

func RespondHTTP(rw http.ResponseWriter, body interface{}, status int)

RespondHTTP will marshall the response body as JSON and write it to the response writer This function signature was chosen to make it substitutable for http.Error This does not end the requset, but does write the header. Care should be taken to close the response after this has been called

func RespondV2

func RespondV2(body interface{}, status int, req events.APIGatewayV2HTTPRequest, err error) (events.APIGatewayV2HTTPResponse, error)

RespondV2 will produce a response that will get formatted such that apigateway will modify it's response to the browser

func Serve

Serve handles and responds to the requests using a net/http handler

func ServeV2

ServeV2 handles and responds to the requests using a net/http handler

func SetLogger

func SetLogger(l *slogger.SpalkLogger)

func StartApex

func StartApex(handler http.Handler)

StartApex starts the apex server than marshals requests in/out of the apex shim using stdin/stdout

func StartLambda

func StartLambda(handler http.Handler, fallback lambdaHandlerFunc)

StartLambda ...

func ToApigRequest

func ToApigRequest(req http.Request) (events.APIGatewayProxyRequest, error)

func ToStdLibRequest

func ToStdLibRequest(req events.APIGatewayProxyRequest) (*http.Request, error)

ToStdLibRequest converts the parsed json message into the format expected by the std library

func ToStdLibRequestV2

func ToStdLibRequestV2(req events.APIGatewayV2HTTPRequest) (*http.Request, error)

func ToStdLibResponse

func ToStdLibResponse(resp events.APIGatewayProxyResponse) http.Response

Types

type ResponseWriter

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

ResponseWriter implements the net/http ResponseWriter interface for using stdlib compliant server libraries with apigateway and lambdas

func (*ResponseWriter) GetResponse

func (rw *ResponseWriter) GetResponse() (events.APIGatewayProxyResponse, error)

GetResponse formats the net/http response to how the response is expected by apigateway

func (*ResponseWriter) Header

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

Header returns the map that will be sent with WriteHeader

func (*ResponseWriter) Write

func (rw *ResponseWriter) Write(data []byte) (int, error)

func (*ResponseWriter) WriteHeader

func (rw *ResponseWriter) WriteHeader(status int)

WriteHeader sets the response code in the embeded response object To be compliant with the http spec for the interface it should write the headers to the client, but we can't control that

type ResponseWriterV2

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

ResponseWriterV2 implements the net/http ResponseWriterV2 interface for using stdlib compliant server libraries with apigatewayv2 and lambdas

func (*ResponseWriterV2) GetResponse

GetResponse formats the net/http response to how the response is expected by apigateway

func (*ResponseWriterV2) Header

func (rw *ResponseWriterV2) Header() http.Header

Header returns the map that will be sent with WriteHeader

func (*ResponseWriterV2) Write

func (rw *ResponseWriterV2) Write(data []byte) (int, error)

func (*ResponseWriterV2) WriteHeader

func (rw *ResponseWriterV2) WriteHeader(status int)

WriteHeader sets the response code in the embeded response object To be compliant with the http spec for the interface it should write the headers to the client, but we can't control that

Jump to

Keyboard shortcuts

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