usps

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package usps is an unofficial Go client for USPS REST APIs v3.

Overview

  • OAuth 2.0 V3 client-credentials (Bearer)
  • Payments v3 authorization for domestic labels
  • Typed OpenAPI clients: Addresses / Labels / Prices / Tracking

Generated OpenAPI clients live in internal/generated and are not imported by downstream modules directly; use this package instead.

This project is not affiliated with USPS. See DISCLAIMER.md at the module root. Do not use legacy eVS / Web Tools XML.

Code generated by generate.sh from scripts/manifest.yaml. DO NOT EDIT.

Index

Constants

View Source
const (
	// EnvTEM is the USPS test environment (apis-tem.usps.com).
	EnvTEM = "tem"
	// EnvSandbox is an alias for TEM (Adapter / credentials may use "sandbox").
	EnvSandbox = "sandbox"
	// EnvProduction is production (apis.usps.com).
	EnvProduction = "production"
)

Variables

This section is empty.

Functions

func BaseURL

func BaseURL(env string, override ...string) string

BaseURL returns the USPS API host for env (tem|production) or override.

func BaseURLFromCreds

func BaseURLFromCreds(cr Creds) string

BaseURLFromCreds resolves the API base from a Creds bundle.

func NormalizeEnv

func NormalizeEnv(env string) string

NormalizeEnv lowercases and maps sandbox→tem; empty defaults to tem.

func ServerURL

func ServerURL(env, apiPackage string) string

ServerURL returns the USPS API base URL for a package and environment. env is "production" or anything else (tem/sandbox).

Types

type APIError

type APIError struct {
	Op         string
	StatusCode int
	Message    string
	Body       string
	Err        error
}

APIError is a normalized USPS / transport error.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

type AddressAdditionalInfo

type AddressAdditionalInfo = addresses.AddressAdditionalInfo

Addresses API types.

type AddressResponse

type AddressResponse = addresses.AddressResponse

Addresses API types.

type AddressesClient

type AddressesClient = addresses.ClientWithResponses

Addresses API types.

type AddressesRequestEditor

type AddressesRequestEditor = addresses.RequestEditorFn

Addresses API types.

type BaseRateOption

type BaseRateOption = prices.BaseRateOption

Prices API types (portal Domestic Prices).

type BaseRatesQuery

type BaseRatesQuery = prices.BaseRatesQuery

Prices API types (portal Domestic Prices).

type BaseRatesQueryAccountType

type BaseRatesQueryAccountType = prices.BaseRatesQueryAccountType

Prices API types (portal Domestic Prices).

type BaseRatesQueryDestinationEntryFacilityType

type BaseRatesQueryDestinationEntryFacilityType = prices.BaseRatesQueryDestinationEntryFacilityType

Prices API types (portal Domestic Prices).

type BaseRatesQueryProcessingCategory

type BaseRatesQueryProcessingCategory = prices.BaseRatesQueryProcessingCategory

Prices API types (portal Domestic Prices).

type BaseRatesQueryRateIndicator

type BaseRatesQueryRateIndicator = prices.BaseRatesQueryRateIndicator

Prices API types (portal Domestic Prices).

type BaseRatesSearchRequest

type BaseRatesSearchRequest = prices.BaseRatesQuery

Backward-compatible aliases for the focused prices seed.

type BaseRatesSearchResponse

type BaseRatesSearchResponse = prices.BaseRateOption

Prices API types (portal Domestic Prices).

type CancelLabelParams

type CancelLabelParams = labels.DeleteLabelByTrackingParams

Labels API types (portal Labels v3).

type Client

type Client struct {
	HTTP     *http.Client
	TokCache *tokenCache
	PayCache *tokenCache
	// contains filtered or unexported fields
}

Client talks to USPS APIs (OAuth + payment auth + typed API accessors).

func New

func New(cfg Config) *Client

New builds a Client.

func (*Client) AccessToken

func (c *Client) AccessToken(ctx context.Context, cr Creds) (string, error)

AccessToken fetches (or returns cached) OAuth client-credentials token.

func (*Client) Addresses

func (c *Client) Addresses(ctx context.Context, cr Creds) (*AddressesClient, error)

Addresses returns a typed Addresses client with Bearer auth.

func (*Client) AuthHeaders

func (c *Client) AuthHeaders(ctx context.Context, cr Creds) (map[string]string, error)

AuthHeaders returns Bearer + Content-Type for ordinary calls.

func (*Client) Environment

func (c *Client) Environment() string

Environment returns the configured environment name.

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient returns the underlying HTTP client.

func (*Client) Labels

func (c *Client) Labels(ctx context.Context, cr Creds) (*LabelsClient, error)

Labels returns a typed Labels client with Bearer auth. Callers must still pass CreateLabelParams / GetLabelParams / CancelLabelParams with X-Payment-Authorization-Token (see PaymentToken).

func (*Client) LabelsWithPayment

func (c *Client) LabelsWithPayment(ctx context.Context, cr Creds) (*LabelsClient, PaymentAuth, error)

LabelsWithPayment returns Labels client plus payment-auth params for label ops.

func (*Client) PaymentHeaders

func (c *Client) PaymentHeaders(ctx context.Context, cr Creds) (map[string]string, error)

PaymentHeaders returns Bearer + payment authorization headers for label ops.

func (*Client) PaymentToken

func (c *Client) PaymentToken(ctx context.Context, cr Creds) (string, error)

PaymentToken fetches (or returns cached) payment authorization token.

func (*Client) Prices

func (c *Client) Prices(ctx context.Context, cr Creds) (*PricesClient, error)

Prices returns a typed Prices client with Bearer auth.

func (*Client) Tracking

func (c *Client) Tracking(ctx context.Context, cr Creds) (*TrackingClient, error)

Tracking returns a typed Tracking client with Bearer auth.

type Config

type Config struct {
	ClientID      string
	ClientSecret  string
	CRID          string
	MID           string
	ManifestMID   string
	AccountNumber string
	AccountType   string
	Environment   string // tem (default) | production | sandbox→tem
	BaseURL       string // optional override

	HTTPClient *http.Client
	Timeout    time.Duration
	MaxRetries int
	Logger     Logger
}

Config holds USPS credentials and runtime options.

type CreateLabelJSONRequestBody

type CreateLabelJSONRequestBody = labels.PostLabelJSONRequestBody

Labels API types (portal Labels v3).

type CreateLabelParams

type CreateLabelParams = labels.PostLabelParams

Labels API types (portal Labels v3).

type CreateLabelRequest

type CreateLabelRequest = labels.LabelRequest

Labels API types (portal Labels v3).

type Creds

type Creds struct {
	ClientID      string
	ClientSecret  string
	CRID          string
	MID           string
	ManifestMID   string
	AccountNumber string
	AccountType   string
	Environment   string
	BaseURL       string
}

Creds are USPS API credentials (used by adapters).

type CustomerReference

type CustomerReference = labels.DomesticCustomerReference

Labels API types (portal Labels v3).

type Email

type Email = labels.Email

Labels API types (portal Labels v3).

type GetAddressParams

type GetAddressParams = addresses.GetAddressParams

Addresses API types.

type GetLabelParams

Labels API types (portal Labels v3).

type GetPackageTrackingBody

type GetPackageTrackingBody = tracking.GetPackageTrackingJSONRequestBody

Tracking API types (portal Tracking v3r2 — POST body).

type ImageInfo

type ImageInfo = labels.ImageInfo

Labels API types (portal Labels v3).

type LabelAddress

type LabelAddress = labels.DomesticLabelAddress

Labels API types (portal Labels v3).

type LabelImageType

type LabelImageType = labels.LabelRequestImageInfoImageType

Labels API types (portal Labels v3).

type LabelLabelType

type LabelLabelType = labels.LabelRequestImageInfoLabelType

Labels API types (portal Labels v3).

type LabelMetadata

type LabelMetadata = labels.LabelMetadata

Labels API types (portal Labels v3).

type LabelReprintImageInfo

type LabelReprintImageInfo = labels.LabelReprintImageInfo

Labels API types (portal Labels v3).

type LabelReprintRequest

type LabelReprintRequest = labels.LabelReprintRequest

Labels API types (portal Labels v3).

type LabelRequestImageInfo

type LabelRequestImageInfo = labels.LabelRequest_ImageInfo

Labels API types (portal Labels v3).

type LabelResponse

type LabelResponse = labels.LabelMultiPartResponse

Labels API types (portal Labels v3).

type LabelToAddress

type LabelToAddress = labels.DomesticLabelToAddress

Labels API types (portal Labels v3).

type LabelsClient

type LabelsClient = labels.ClientWithResponses

Labels API types (portal Labels v3).

type LabelsRequestEditor

type LabelsRequestEditor = labels.RequestEditorFn

Labels API types (portal Labels v3).

type Logger

type Logger interface {
	Debugf(format string, args ...any)
	Errorf(format string, args ...any)
}

Logger is a minimal structured logger hook.

type MailClass

type MailClass = prices.MailClass

Prices API types (portal Domestic Prices).

type PackageDescription

type PackageDescription = labels.DomesticPackageDescription

Labels API types (portal Labels v3).

type PackageDescriptionUnion

type PackageDescriptionUnion = labels.LabelRequest_PackageDescription

Labels API types (portal Labels v3).

func PackageDescriptionFrom

func PackageDescriptionFrom(v PackageDescription) (PackageDescriptionUnion, error)

PackageDescriptionFrom builds the OpenAPI union for LabelRequest.packageDescription.

type PackageDestinationEntryFacilityType

type PackageDestinationEntryFacilityType = labels.DomesticPackageDescriptionDestinationEntryFacilityType

Labels API types (portal Labels v3).

type PackageDimensionsUOM

type PackageDimensionsUOM = labels.DomesticPackageDescriptionDimensionsUOM

Labels API types (portal Labels v3).

type PackageMailClass

Labels API types (portal Labels v3).

type PackageProcessingCategory

type PackageProcessingCategory = labels.DomesticPackageDescriptionProcessingCategory

Labels API types (portal Labels v3).

type PackageRateIndicator

type PackageRateIndicator = labels.DomesticPackageDescriptionRateIndicator

Labels API types (portal Labels v3).

type PackageWeightUOM

Labels API types (portal Labels v3).

type PaymentAuth

type PaymentAuth = labels.XPaymentAuthorizationToken

Labels API types (portal Labels v3).

type Phone

type Phone = labels.Phone

Labels API types (portal Labels v3).

type PostBaseRatesSearchJSONRequestBody

type PostBaseRatesSearchJSONRequestBody = prices.PostBaseRatesSearchJSONRequestBody

Prices API types (portal Domestic Prices).

type PriceType

type PriceType = prices.PriceType

Prices API types (portal Domestic Prices).

type PricesClient

type PricesClient = prices.ClientWithResponses

Prices API types (portal Domestic Prices).

type PricesRequestEditor

type PricesRequestEditor = prices.RequestEditorFn

Prices API types (portal Domestic Prices).

type ProofOfDelivery

type ProofOfDelivery = tracking.ProofOfDeliveryRequest

Tracking API types (portal Tracking v3r2 — POST body).

type ReprintImageType

type ReprintImageType = labels.LabelReprintImageInfoImageType

Labels API types (portal Labels v3).

type SearchBaseRatesJSONRequestBody

type SearchBaseRatesJSONRequestBody = prices.PostBaseRatesSearchJSONRequestBody

Prices API types (portal Domestic Prices).

type StandardizedAddress

type StandardizedAddress = addresses.DomesticAddress

Addresses API types.

type State

type State = labels.State

Labels API types (portal Labels v3).

type TrackingClient

type TrackingClient = tracking.ClientWithResponses

Tracking API types (portal Tracking v3r2 — POST body).

type TrackingDetail

type TrackingDetail = tracking.TrackingDetail

Tracking API types (portal Tracking v3r2 — POST body).

type TrackingNumber

type TrackingNumber = labels.TrackingNumber

Labels API types (portal Labels v3).

type TrackingRequest

type TrackingRequest = tracking.TrackingRequest

Tracking API types (portal Tracking v3r2 — POST body).

type TrackingRequestBody

type TrackingRequestBody = tracking.TrackingRequestBody

Tracking API types (portal Tracking v3r2 — POST body).

type TrackingRequestEditor

type TrackingRequestEditor = tracking.RequestEditorFn

Tracking API types (portal Tracking v3r2 — POST body).

type TrackingResponse

type TrackingResponse = tracking.TrackingDetails

Tracking API types (portal Tracking v3r2 — POST body).

Jump to

Keyboard shortcuts

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