Documentation
¶
Index ¶
- Constants
- Variables
- func AsLambdaExtension() bool
- func AsLambdaHandler() bool
- func NewRequest(event json.RawMessage) (*http.Request, error)
- func OnLambdaRuntime() bool
- func Run(address, prefix string, mux http.Handler)
- func RunWithContext(ctx context.Context, address, prefix string, mux http.Handler)
- type LogEvent
- type LogStream
- type Message
- type Request
- type RequestContextV1
- type RequestContextV2
- type RequestV1
- type RequestV2
- type RequetContext
- type Response
- type ResponseWriter
- type Ridge
- type StreamingResponseWriter
- func (w *StreamingResponseWriter) Close() error
- func (w *StreamingResponseWriter) Flush()
- func (w *StreamingResponseWriter) Header() http.Header
- func (w *StreamingResponseWriter) Response() *events.LambdaFunctionURLStreamingResponse
- func (w *StreamingResponseWriter) Wait()
- func (w *StreamingResponseWriter) Write(b []byte) (int, error)
- func (w *StreamingResponseWriter) WriteHeader(code int)
Examples ¶
Constants ¶
const PayloadVersionHeaderName = "X-Lambda-Payload-Version"
PayloadVersionHeaderName is a header name for payload version
const RequestIDHeaderName = "X-Amzn-RequestId"
const (
StreamingResponseEnv = "RIDGE_STREAMING_RESPONSE"
)
Variables ¶
var DefaultContentType = "text/plain; charset=utf-8"
DefaultContentType is a default content-type when missing in response.
var PayloadVersion string
PayloadVersion when this variable set, Ridge disables auto detection payload version.
var ProxyProtocol bool
ProxyProtocol is a flag to support PROXY Protocol
var TextMimeTypes = []string{"image/svg+xml", "application/json", "application/xml"}
TextMimeTypes is a list of identified as text.
Functions ¶
func AsLambdaExtension ¶ added in v0.11.3
func AsLambdaExtension() bool
AsLambdaExtension returns true if running on AWS Lambda runtime and run as a Lambda extension
func AsLambdaHandler ¶ added in v0.11.3
func AsLambdaHandler() bool
AsLambdaHandler returns true if running on AWS Lambda runtime and run as a Lambda handler
func NewRequest ¶
func NewRequest(event json.RawMessage) (*http.Request, error)
NewRequest creates *net/http.Request from a Request.
func OnLambdaRuntime ¶ added in v0.11.3
func OnLambdaRuntime() bool
OnLambdaRuntime returns true if running on AWS Lambda runtime - AWS_EXECUTION_ENV is set on AWS Lambda runtime (go1.x) - AWS_LAMBDA_RUNTIME_API is set on custom runtime (provided.*)
Types ¶
type LogStream ¶
type LogStream struct {
MessageType string `json:"messageType"`
Owner string `json:"owner"`
LogGroup string `json:"logGroup"`
LogStream string `json:"logStream"`
SubscriptionFilters []string `json:"subscriptionFilters"`
LogEvents []LogEvent `json:"logEvents"`
}
func DecodeLogStream ¶
func DecodeLogStream(event json.RawMessage) (*LogStream, error)
DecodeLogStream decodes CloudwatchLogs stream passed to a lambda function.
Example ¶
package main
import (
"encoding/json"
"log"
"github.com/aws/aws-lambda-go/lambda"
"github.com/fujiwara/ridge"
)
func main() {
lambda.Start(func(event json.RawMessage) (any, error) {
logStream, err := ridge.DecodeLogStream(event)
if err != nil {
return nil, err
}
for _, e := range logStream.LogEvents {
//
log.Println(e.Message)
}
return "", nil
})
}
Output:
type Message ¶
type Message struct {
Awslogs struct {
Data []byte `json:"data"`
} `json:"awslogs"`
}
type RequestContextV1 ¶ added in v0.2.0
type RequestContextV1 struct {
AccountID string `json:"accountId"`
APIID string `json:"apiId"`
HTTPMethod string `json:"httpMethod"`
Identity map[string]string `json:"identity"`
RequestID string `json:"requestId"`
ResourceID string `json:"resourceId"`
ResourcePath string `json:"resourcePath"`
Stage string `json:"stage"`
}
RequestContextV1 represents request contest object (v1.0).
type RequestContextV2 ¶ added in v0.2.0
type RequestContextV2 struct {
AccountID string `json:"accountId"`
APIID string `json:"apiId"`
DomainName string `json:"domainName"`
DomainPrefix string `json:"domainPrefix"`
HTTP struct {
Method string `json:"method"`
Path string `json:"path"`
Protocol string `json:"protocol"`
SourceIP string `json:"sourceIp"`
UserAgent string `json:"userAgent"`
} `json:"http"`
RequestID string `json:"requestId"`
RouteID string `json:"routeId"`
RouteKey string `json:"routeKey"`
Stage string `json:"stage"`
Time string `json:"time"`
TimeEpoch int64 `json:"timeEpoch"`
}
RequestContextV2 represents request context for v2.0
type RequestV1 ¶ added in v0.2.0
type RequestV1 struct {
Version string `json:"version"`
Body string `json:"body"`
Headers map[string]string `json:"headers"`
MultiValueHeaders http.Header `json:"multiValueHeaders"`
HTTPMethod string `json:"httpMethod"`
Path string `json:"path"`
PathParameters map[string]string `json:"pathParameters"`
QueryStringParameters map[string]string `json:"queryStringParameters"`
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"`
Resource string `json:"resource"`
StageVariables map[string]string `json:"stageVariables"`
RequestContext RequestContextV1 `json:"requestContext"`
IsBase64Encoded bool `json:"isBase64Encoded"`
}
RequestV1 represents an HTTP request received by an API Gateway proxy integrations. (v1.0) https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
type RequestV2 ¶ added in v0.2.0
type RequestV2 struct {
Version string `json:"version"`
RouteKey string `json:"routeKey"`
RawPath string `json:"rawPath"`
RawQueryString string `json:"rawQueryString"`
Cookies []string `json:"cookies"`
Headers map[string]string `json:"headers"`
QueryStringParameters map[string]string `json:"queryStringParameters"`
RequestContext RequestContextV2 `json:"requestContext"`
Body string `json:"body"`
IsBase64Encoded bool `json:"isBase64Encoded"`
StageVariables map[string]string `json:"stageVariables"`
}
RequestV2 represents an HTTP request received by an API Gateway proxy integrations. (v2.0) https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
type RequetContext ¶ added in v0.2.0
type RequetContext = RequestContextV1
RequstContext is alias to RequestContextV1
type Response ¶
type Response struct {
StatusCode int `json:"statusCode"`
Headers map[string]string `json:"headers"`
MultiValueHeaders http.Header `json:"multiValueHeaders"`
Cookies []string `json:"cookies,omitempty"`
Body string `json:"body"`
IsBase64Encoded bool `json:"isBase64Encoded"`
}
Response represents a response for API Gateway proxy integration.
type ResponseWriter ¶
ResponseWriter represents a response writer implements http.ResponseWriter.
func NewResponseWriter ¶
func NewResponseWriter() *ResponseWriter
NewResponseWriter creates ResponseWriter
func (*ResponseWriter) Header ¶
func (w *ResponseWriter) Header() http.Header
func (*ResponseWriter) Response ¶
func (w *ResponseWriter) Response() Response
func (*ResponseWriter) ResponseFor ¶ added in v0.13.1
func (w *ResponseWriter) ResponseFor(version string) Response
ResponseFor creates a response with version-specific behavior
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(code int)
type Ridge ¶ added in v0.9.0
type Ridge struct {
Address string
Prefix string
Mux http.Handler
RequestBuilder func(json.RawMessage) (*http.Request, error)
TermHandler func()
ProxyProtocol bool
StreamingResponse bool
}
Ridge is a struct to run http handler on AWS Lambda runtime or net/http's server.
func (*Ridge) Run ¶ added in v0.9.0
func (r *Ridge) Run()
Run runs http handler on AWS Lambda runtime or net/http's server.
func (*Ridge) RunWithContext ¶ added in v0.9.0
RunWithContext runs http handler on AWS Lambda runtime or net/http's server with context.
type StreamingResponseWriter ¶ added in v0.13.0
type StreamingResponseWriter struct {
// contains filtered or unexported fields
}
StreamingResponseWriter is a response writer for streaming response.
func NewStreamingResponseWriter ¶ added in v0.13.0
func NewStreamingResponseWriter() *StreamingResponseWriter
NewStreamingResponseWriter creates StreamingResponseWriter
func (*StreamingResponseWriter) Close ¶ added in v0.13.0
func (w *StreamingResponseWriter) Close() error
func (*StreamingResponseWriter) Flush ¶ added in v0.13.0
func (w *StreamingResponseWriter) Flush()
func (*StreamingResponseWriter) Header ¶ added in v0.13.0
func (w *StreamingResponseWriter) Header() http.Header
func (*StreamingResponseWriter) Response ¶ added in v0.13.0
func (w *StreamingResponseWriter) Response() *events.LambdaFunctionURLStreamingResponse
func (*StreamingResponseWriter) Wait ¶ added in v0.13.0
func (w *StreamingResponseWriter) Wait()
func (*StreamingResponseWriter) Write ¶ added in v0.13.0
func (w *StreamingResponseWriter) Write(b []byte) (int, error)
func (*StreamingResponseWriter) WriteHeader ¶ added in v0.13.0
func (w *StreamingResponseWriter) WriteHeader(code int)