awsjson

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 6 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 Blob added in v0.2.0

func Blob(p map[string]any, key string) ([]byte, *awshttp.APIError)

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 Bool added in v0.2.0

func Bool(p map[string]any, key string) bool

Bool returns the bool at key, or false when absent or not a bool.

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

func Int added in v0.2.0

func Int(p map[string]any, key string, def int) int

Int returns the number at key as an int, or def when absent or not a number.

func Int64 added in v0.2.0

func Int64(p map[string]any, key string, def int64) int64

Int64 returns the number at key as an int64, or def when absent or not a number.

func Str added in v0.2.0

func Str(p map[string]any, key string) string

Str returns the string at key, or "" when absent or not a string.

func StrMap added in v0.2.0

func StrMap(p map[string]any, key string) map[string]string

StrMap returns the string-valued object at key; non-string values are dropped. Absent keys return nil.

func Strs added in v0.2.0

func Strs(p map[string]any, key string) []string

Strs returns the string list at key; non-string elements are dropped. Absent keys return nil.

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