{"modulePath":"github.com/LF-Engineering/aws-lambda-go-api-proxy","version":"v0.3.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package core\n\nPackage core provides utility methods that help convert proxy events into an http.Request and http.ResponseWriter\n\nPackage core provides utility methods that help convert proxy events into an http.Request and http.ResponseWriter\n\n## Constants\n\n```go\nconst APIGwContextHeader = \"X-GoLambdaProxy-ApiGw-Context\"\n```\nAPIGwContextHeader is the custom header key used to store the API Gateway context. To access the Context properties use the GetAPIGatewayContext method of the RequestAccessor object.\n\n```go\nconst APIGwStageVarsHeader = \"X-GoLambdaProxy-ApiGw-StageVars\"\n```\nAPIGwStageVarsHeader is the custom header key used to store the API Gateway stage variables. To access the stage variable values use the GetAPIGatewayStageVars method of the RequestAccessor object.\n\n```go\nconst CustomHostVariable = \"GO_API_HOST\"\n```\nCustomHostVariable is the name of the environment variable that contains the custom hostname for the request. If this variable is not set the framework reverts to \\`DefaultServerAddress\\`. The value for a custom host should include a protocol: [http://my-custom.host.com](http://my-custom.host.com)\n\n```go\nconst DefaultServerAddress = \"https://aws-serverless-go-api.com\"\n```\nDefaultServerAddress is prepended to the path of each incoming reuqest\n\n## Functions\n\n```go\nfunc GatewayTimeout() events.APIGatewayProxyResponse\n```\nGatewayTimeout returns a dafault Gateway Timeout (504) response\n\n```go\nfunc GetAPIGatewayContextFromContext(ctx context.Context) (events.APIGatewayProxyRequestContext, bool)\n```\nGetAPIGatewayContextFromContext retrieve APIGatewayProxyRequestContext from context.Context\n\n```go\nfunc GetRuntimeContextFromContext(ctx context.Context) (*lambdacontext.LambdaContext, bool)\n```\nGetRuntimeContextFromContext retrieve Lambda Runtime Context from context.Context\n\n```go\nfunc GetStageVarsFromContext(ctx context.Context) (map[string]string, bool)\n```\nGetStageVarsFromContext retrieve stage variables from context\n\n```go\nfunc NewLoggedError(format string, a ...interface{}) error\n```\nNewLoggedError generates a new error and logs it to stdout\n\n## Types\n\n```go\ntype ProxyResponseWriter struct {\n\t// contains filtered or unexported fields\n}\n```\nProxyResponseWriter implements http.ResponseWriter and adds the method necessary to return an events.APIGatewayProxyResponse object\n\n```go\nfunc NewProxyResponseWriter() *ProxyResponseWriter\n```\nNewProxyResponseWriter returns a new ProxyResponseWriter object. The object is initialized with an empty map of headers and a status code of -1\n\n```go\nfunc (r *ProxyResponseWriter) GetProxyResponse() (events.APIGatewayProxyResponse, error)\n```\nGetProxyResponse converts the data passed to the response writer into an events.APIGatewayProxyResponse object. Returns a populated proxy response object. If the response is invalid, for example has no headers or an invalid status code returns an error.\n\n```go\nfunc (r *ProxyResponseWriter) Header() http.Header\n```\nHeader implementation from the http.ResponseWriter interface.\n\n```go\nfunc (r *ProxyResponseWriter) Write(body []byte) (int, error)\n```\nWrite sets the response body in the object. If no status code was set before with the WriteHeader method it sets the status for the response to 200 OK.\n\n```go\nfunc (r *ProxyResponseWriter) WriteHeader(status int)\n```\nWriteHeader sets a status code for the response. This method is used for error responses.\n\n```go\ntype RequestAccessor struct {\n\t// contains filtered or unexported fields\n}\n```\nRequestAccessor objects give access to custom API Gateway properties in the request.\n\n```go\nfunc (r *RequestAccessor) EventToRequest(req events.APIGatewayProxyRequest) (*http.Request, error)\n```\nEventToRequest converts an API Gateway proxy event into an http.Request object. Returns the populated request maintaining headers\n\n```go\nfunc (r *RequestAccessor) EventToRequestWithContext(ctx context.Context, req events.APIGatewayProxyRequest) (*http.Request, error)\n```\nEventToRequestWithContext converts an API Gateway proxy event and context into an http.Request object. Returns the populated http request with lambda context, stage variables and APIGatewayProxyRequestContext as part of its context. Access those using GetAPIGatewayContextFromContext, GetStageVarsFromContext and GetRuntimeContextFromContext functions in this package.\n\n```go\nfunc (r *RequestAccessor) GetAPIGatewayContext(req *http.Request) (events.APIGatewayProxyRequestContext, error)\n```\nGetAPIGatewayContext extracts the API Gateway context object from a request's custom header. Returns a populated events.APIGatewayProxyRequestContext object from the request.\n\n```go\nfunc (r *RequestAccessor) GetAPIGatewayStageVars(req *http.Request) (map[string]string, error)\n```\nGetAPIGatewayStageVars extracts the API Gateway stage variables from a request's custom header. Returns a map\\[string]string of the stage variables and their values from the request.\n\n```go\nfunc (r *RequestAccessor) ProxyEventToHTTPRequest(req events.APIGatewayProxyRequest) (*http.Request, error)\n```\nProxyEventToHTTPRequest converts an API Gateway proxy event into a http.Request object. Returns the populated http request with additional two custom headers for the stage variables and API Gateway context. To access these properties use the GetAPIGatewayStageVars and GetAPIGatewayContext method of the RequestAccessor object.\n\n```go\nfunc (r *RequestAccessor) StripBasePath(basePath string) string\n```\nStripBasePath instructs the RequestAccessor object that the given base path should be removed from the request path before sending it to the framework for routing. This is used when API Gateway is configured with base path mappings in custom domain names.\n\n","path":"github.com/LF-Engineering/aws-lambda-go-api-proxy/core","name":"core","synopsis":"Package core provides utility methods that help convert proxy events into an http.Request and http.ResponseWriter Package core provides utility methods that help convert proxy events into an http.Request and http.ResponseWriter","isRedistributable":true}
