Documentation
¶
Overview ¶
Package awsjson implements the AWS JSON 1.0/1.1 protocols: POST / with an X-Amz-Target header naming the action ("Prefix.Action"), a JSON body, and JSON responses. DynamoDB and modern SQS speak 1.0; KMS, SSM, Secrets Manager and EventBridge speak 1.1. The two versions differ only in the Content-Type they echo and minor error-shape history — one codec covers both.
Errors travel as HTTP status + {"__type":"Code","message":"..."} plus the x-amzn-ErrorType header, which is what both SDK generations match on.
Index ¶
- func Blob(p map[string]any, key string) ([]byte, *awshttp.APIError)
- func Bool(p map[string]any, key string) bool
- func DecodeBody(r *http.Request, dst any) *awshttp.APIError
- func Int(p map[string]any, key string, def int) int
- func Int64(p map[string]any, key string, def int64) int64
- func Str(p map[string]any, key string) string
- func StrMap(p map[string]any, key string) map[string]string
- func Strs(p map[string]any, key string) []string
- type API
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Blob ¶ added in v0.2.0
Blob decodes the base64 blob at key (JSON-protocol blobs travel base64). Absent or empty keys return (nil, nil); malformed base64 is a ValidationException.
func DecodeBody ¶
DecodeBody reads and unmarshals the JSON request body into dst. An empty body decodes as an empty object (several actions take no parameters and some SDKs send nothing at all).
func Int ¶ added in v0.2.0
Int returns the number at key as an int, or def when absent or not a number.
func Int64 ¶ added in v0.2.0
Int64 returns the number at key as an int64, or def when absent or not a number.
Types ¶
type API ¶
type API struct {
// TargetPrefix is the service's X-Amz-Target prefix, e.g. "AmazonSQS",
// "DynamoDB_20120810", "TrentService".
TargetPrefix string
// JSONVersion is "1.0" or "1.1" (sets the response Content-Type).
JSONVersion string
}
API decodes requests and renders responses for one JSON-protocol service.
func (API) Action ¶
Action extracts the action name from the X-Amz-Target header, validating the service prefix.
func (API) ContentType ¶
ContentType returns the protocol's content type, e.g. "application/x-amz-json-1.0".
func (API) Write ¶
func (a API) Write(w http.ResponseWriter, result any)
Write renders a success response. A nil result writes an empty JSON object (the SDKs expect a body even for result-less actions).
func (API) WriteError ¶
func (a API) WriteError(w http.ResponseWriter, e *awshttp.APIError)
WriteError renders the JSON-protocol error shape with e's HTTP status.