Documentation
¶
Index ¶
- Constants
- func ParseRequestBody(r *http.Request) ([]byte, error)
- func WriteErrorResponse(w http.ResponseWriter, awsErr *AWSError, format ResponseFormat) error
- func WriteJSONResponse(w http.ResponseWriter, statusCode int, body any) error
- func WriteXMLResponse(w http.ResponseWriter, statusCode int, body any) error
- type AWSError
- type Action
- type CallerIdentity
- type RequestContext
- type RequestValidator
- type Response
- type ResponseFormat
- type Service
- type Snapshotable
Constants ¶
const MaxRequestBodySize = 10 * 1024 * 1024
MaxRequestBodySize is the maximum allowed request body size (10 MB).
Variables ¶
This section is empty.
Functions ¶
func ParseRequestBody ¶
ParseRequestBody reads and returns the full body from an HTTP request.
func WriteErrorResponse ¶
func WriteErrorResponse(w http.ResponseWriter, awsErr *AWSError, format ResponseFormat) error
WriteErrorResponse writes an AWSError in the specified format.
func WriteJSONResponse ¶
func WriteJSONResponse(w http.ResponseWriter, statusCode int, body any) error
WriteJSONResponse marshals body as JSON and writes it with Content-Type application/x-amz-json-1.1.
func WriteXMLResponse ¶
func WriteXMLResponse(w http.ResponseWriter, statusCode int, body any) error
WriteXMLResponse marshals body as XML and writes it with Content-Type text/xml.
Types ¶
type AWSError ¶
type AWSError struct {
XMLName xml.Name `xml:"Error" json:"-"`
Code string `xml:"Code" json:"-"`
Message string `xml:"Message" json:"-"`
// contains filtered or unexported fields
}
AWSError represents an AWS-compatible error with XML and JSON marshaling support.
func ErrAccessDenied ¶
ErrAccessDenied returns a 403 AccessDenied error for an action.
func ErrAlreadyExists ¶
ErrAlreadyExists returns a 409 AlreadyExists error for a named resource.
func ErrNotFound ¶
ErrNotFound returns a 404 NoSuchKey error for a named resource.
func ErrValidation ¶
ErrValidation returns a 400 ValidationError with the given message.
func NewAWSError ¶
NewAWSError creates a new AWSError with the given code, message, and HTTP status code.
func (*AWSError) MarshalJSON ¶
MarshalJSON outputs the AWS JSON error format with __type and Message fields.
func (*AWSError) StatusCode ¶
StatusCode returns the HTTP status code for this error.
type Action ¶
type Action struct {
Name string
Method string
IAMAction string
Validator RequestValidator
}
Action describes a single AWS API action that a service supports.
type CallerIdentity ¶
type CallerIdentity struct {
AccountID string
ARN string
UserID string
AccessKeyID string
IsRoot bool
}
CallerIdentity holds identity information about the entity making a request.
type RequestContext ¶
type RequestContext struct {
Action string
Region string
AccountID string
Identity *CallerIdentity
RawRequest *http.Request
Body []byte
Params map[string]string
Service string
}
RequestContext carries all parsed request data into a service handler.
type RequestValidator ¶
type RequestValidator func(ctx *RequestContext) *AWSError
RequestValidator validates an incoming request and returns an AWSError on failure.
type Response ¶
type Response struct {
StatusCode int
Body any
Format ResponseFormat
Headers map[string]string
RawBody []byte // if set, write these bytes directly instead of marshaling Body
RawContentType string // Content-Type to use when writing RawBody
}
Response holds the components of an HTTP response before it is written.
type ResponseFormat ¶
type ResponseFormat int
ResponseFormat indicates the wire format for a response.
const ( FormatXML ResponseFormat = iota FormatJSON ResponseFormat = iota )
type Service ¶
type Service interface {
Name() string
Actions() []Action
HandleRequest(ctx *RequestContext) (*Response, error)
HealthCheck() error
}
Service is the interface every AWS service mock must implement.
type Snapshotable ¶
type Snapshotable interface {
ExportState() (json.RawMessage, error)
ImportState(data json.RawMessage) error
}
Snapshotable is implemented by services that support state export/import.