awsjson

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBody

func DecodeBody(r *http.Request, dst any) *awshttp.APIError

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).

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

func (a API) Action(r *http.Request) (string, *awshttp.APIError)

Action extracts the action name from the X-Amz-Target header, validating the service prefix.

func (API) ContentType

func (a API) ContentType() string

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.

Jump to

Keyboard shortcuts

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