service

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const MaxRequestBodySize = 10 * 1024 * 1024

MaxRequestBodySize is the maximum allowed request body size (10 MB).

Variables

This section is empty.

Functions

func ParseRequestBody

func ParseRequestBody(r *http.Request) ([]byte, error)

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

func ErrAccessDenied(action string) *AWSError

ErrAccessDenied returns a 403 AccessDenied error for an action.

func ErrAlreadyExists

func ErrAlreadyExists(resourceType, name string) *AWSError

ErrAlreadyExists returns a 409 AlreadyExists error for a named resource.

func ErrNotFound

func ErrNotFound(resourceType, name string) *AWSError

ErrNotFound returns a 404 NoSuchKey error for a named resource.

func ErrValidation

func ErrValidation(message string) *AWSError

ErrValidation returns a 400 ValidationError with the given message.

func NewAWSError

func NewAWSError(code, message string, statusCode int) *AWSError

NewAWSError creates a new AWSError with the given code, message, and HTTP status code.

func (*AWSError) Error

func (e *AWSError) Error() string

Error implements the error interface.

func (*AWSError) MarshalJSON

func (e *AWSError) MarshalJSON() ([]byte, error)

MarshalJSON outputs the AWS JSON error format with __type and Message fields.

func (*AWSError) StatusCode

func (e *AWSError) StatusCode() int

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.

Jump to

Keyboard shortcuts

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