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
- func BaseURL(env string, override ...string) string
- func BaseURLFromCreds(cr Creds) string
- func NormalizeEnv(env string) string
- func ServerURL(env, apiPackage string) string
- type APIError
- type AddressAdditionalInfo
- type AddressResponse
- type AddressesClient
- type AddressesRequestEditor
- type BaseRateOption
- type BaseRatesQuery
- type BaseRatesQueryAccountType
- type BaseRatesQueryDestinationEntryFacilityType
- type BaseRatesQueryProcessingCategory
- type BaseRatesQueryRateIndicator
- type BaseRatesSearchRequest
- type BaseRatesSearchResponse
- type CancelLabelParams
- type Client
- func (c *Client) AccessToken(ctx context.Context, cr Creds) (string, error)
- func (c *Client) Addresses(ctx context.Context, cr Creds) (*AddressesClient, error)
- func (c *Client) AuthHeaders(ctx context.Context, cr Creds) (map[string]string, error)
- func (c *Client) Environment() string
- func (c *Client) HTTPClient() *http.Client
- func (c *Client) Labels(ctx context.Context, cr Creds) (*LabelsClient, error)
- func (c *Client) LabelsWithPayment(ctx context.Context, cr Creds) (*LabelsClient, PaymentAuth, error)
- func (c *Client) PaymentHeaders(ctx context.Context, cr Creds) (map[string]string, error)
- func (c *Client) PaymentToken(ctx context.Context, cr Creds) (string, error)
- func (c *Client) Prices(ctx context.Context, cr Creds) (*PricesClient, error)
- func (c *Client) Tracking(ctx context.Context, cr Creds) (*TrackingClient, error)
- type Config
- type CreateLabelJSONRequestBody
- type CreateLabelParams
- type CreateLabelRequest
- type Creds
- type CustomerReference
- type Email
- type GetAddressParams
- type GetLabelParams
- type GetPackageTrackingBody
- type ImageInfo
- type LabelAddress
- type LabelImageType
- type LabelLabelType
- type LabelMetadata
- type LabelReprintImageInfo
- type LabelReprintRequest
- type LabelRequestImageInfo
- type LabelResponse
- type LabelToAddress
- type LabelsClient
- type LabelsRequestEditor
- type Logger
- type MailClass
- type PackageDescription
- type PackageDescriptionUnion
- type PackageDestinationEntryFacilityType
- type PackageDimensionsUOM
- type PackageMailClass
- type PackageProcessingCategory
- type PackageRateIndicator
- type PackageWeightUOM
- type PaymentAuth
- type Phone
- type PostBaseRatesSearchJSONRequestBody
- type PriceType
- type PricesClient
- type PricesRequestEditor
- type ProofOfDelivery
- type ReprintImageType
- type SearchBaseRatesJSONRequestBody
- type StandardizedAddress
- type State
- type TrackingClient
- type TrackingDetail
- type TrackingNumber
- type TrackingRequest
- type TrackingRequestBody
- type TrackingRequestEditor
- type TrackingResponse
Constants ¶
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 BaseURLFromCreds ¶
BaseURLFromCreds resolves the API base from a Creds bundle.
func NormalizeEnv ¶
NormalizeEnv lowercases and maps sandbox→tem; empty defaults to tem.
Types ¶
type AddressAdditionalInfo ¶
type AddressAdditionalInfo = addresses.AddressAdditionalInfo
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 (*Client) AccessToken ¶
AccessToken fetches (or returns cached) OAuth client-credentials token.
func (*Client) AuthHeaders ¶
AuthHeaders returns Bearer + Content-Type for ordinary calls.
func (*Client) Environment ¶
Environment returns the configured environment name.
func (*Client) HTTPClient ¶
HTTPClient returns the underlying HTTP client.
func (*Client) Labels ¶
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 ¶
PaymentHeaders returns Bearer + payment authorization headers for label ops.
func (*Client) PaymentToken ¶
PaymentToken fetches (or returns cached) payment authorization token.
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 GetLabelParams ¶
type GetLabelParams = labels.PostLabelReprintByTrackingParams
Labels API types (portal Labels v3).
type GetPackageTrackingBody ¶
type GetPackageTrackingBody = tracking.GetPackageTrackingJSONRequestBody
Tracking API types (portal Tracking v3r2 — POST body).
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 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 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 ¶
type PackageMailClass = labels.DomesticPackageDescriptionMailClass
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 ¶
type PackageWeightUOM = labels.DomesticPackageDescriptionWeightUOM
Labels API types (portal Labels v3).
type PaymentAuth ¶
type PaymentAuth = labels.XPaymentAuthorizationToken
Labels API types (portal Labels v3).
type PostBaseRatesSearchJSONRequestBody ¶
type PostBaseRatesSearchJSONRequestBody = prices.PostBaseRatesSearchJSONRequestBody
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 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).