awsmeta

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package awsmeta defines the Metadata struct that carries AWS request-scoped identity (account, region, partition, request ID) and a helper to populate it from an *http.Request.

Storage on context.Context is delegated to pkgs/ctxval — this package exposes a single Key plus thin Set/Get/Region/Account wrappers so service backends pull metadata uniformly without each one defining its own key.

Index

Constants

View Source
const DefaultAccount = "000000000000"

DefaultAccount is the gopherstack default 12-digit account ID.

View Source
const DefaultPartition = "aws"

DefaultPartition is the public AWS commercial partition.

Variables

View Source
var Key = ctxval.NewKey[*Metadata]("awsmeta") //nolint:gochecknoglobals // existing issue.

Key is the context key under which Metadata is stored. Exported so callers that want raw ctxval access (e.g. middleware that wraps Set with logging) can reuse it.

Functions

func Account

func Account(ctx context.Context) string

Account returns Get(ctx).Account.

func Partition

func Partition(ctx context.Context) string

Partition returns Get(ctx).Partition.

func Region

func Region(ctx context.Context) string

Region returns Get(ctx).Region.

func Set

func Set(ctx context.Context, m *Metadata) context.Context

Set returns a child context carrying m. Passing nil is a no-op.

Types

type Metadata

type Metadata struct {
	// Account is the 12-digit AWS account ID.
	Account string
	// Region is the AWS region (e.g. "us-east-1"). Empty for global services.
	Region string
	// Partition is the AWS partition (aws, aws-cn, aws-us-gov).
	Partition string
	// RequestID is the X-Amz-Request-Id correlation value.
	RequestID string
}

Metadata carries AWS request-scoped identity and routing fields.

func FromRequest

func FromRequest(r *http.Request, defaultRegion string) *Metadata

FromRequest builds a Metadata from r. defaultRegion is applied when no region is derivable from the SigV4 scope. Always returns non-nil with Account and Partition populated.

func Get

func Get(ctx context.Context) *Metadata

Get returns the metadata carried on ctx, or a *Metadata with default Account and Partition fields when none was set. The return is never nil so callers can dereference fields without a guard.

Jump to

Keyboard shortcuts

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