usps-sdk

module
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

README

usps-sdk

English | 中文

Unofficial Go SDK for USPS REST APIs v3, generated from OpenAPI specs and wrapped with OAuth2 v3, Payments auth, retries, and a stable facade.

Not affiliated with USPS. You need your own Developer Portal credentials. See DISCLAIMER.md. Do not use legacy eVS / Web Tools XML.

Why this layout

Path Purpose
usps/ Hand-written facade (OAuth, Payments, typed API accessors)
specs/ Portal OpenAPI YAML (committed)
internal/generated/<api>/ oapi-codegen output (committed so go get works)
scripts/ + generate.sh specs/ → preprocess → generate
.cache/specs/ Local preprocess cache (gitignored)

Install

go get github.com/befship/usps-sdk@latest

Specs in this repo

Official portal downloads live under specs/. See specs/README.md.

完整对照见 specs/README.md。本次新增并已 codegen:

Spec Package
oauth2.yaml oauth2
payments.yaml payments
international-prices.yaml internationalprices
locations.yaml locations
service-standards.yaml servicestandards
service-standards-files.yaml servicestandardsfiles
shipment-tracking.yaml shipmenttracking

Quick start

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/befship/usps-sdk/usps"
)

func main() {
	client := usps.New(usps.Config{
		ClientID:     os.Getenv("USPS_CLIENT_ID"),
		ClientSecret: os.Getenv("USPS_CLIENT_SECRET"),
		Environment:  usps.EnvTEM,
	})
	api, err := client.Addresses(context.Background(), usps.Creds{})
	if err != nil {
		panic(err)
	}
	fmt.Println("ready", usps.ServerURL(client.Environment(), "addresses"), api != nil)
}

Endpoints

Environment Host
TEM / test (tem) https://apis-tem.usps.com
Production https://apis.usps.com

Per-API bases (e.g. .../labels/v3) come from ServerURL(env, package).

  • Auth: OAuth 2.0 V3 (POST /oauth2/v3/token)
  • Labels need Payments (POST /payments/v3/payment-authorization)

Regenerate

make generate

# Optional: use another directory of portal YAMLs
SPEC_DIR=/path/to/usps-openapi-downloads make generate

License

Hand-written code: MIT. Generated clients / committed OpenAPI: subject to USPS API terms. See LICENSE and DISCLAIMER.md.

Directories

Path Synopsis
internal
generated/addresses
Package addresses provides primitives to interact with the openapi HTTP API.
Package addresses provides primitives to interact with the openapi HTTP API.
generated/adjustments
Package adjustments provides primitives to interact with the openapi HTTP API.
Package adjustments provides primitives to interact with the openapi HTTP API.
generated/appointments
Package appointments provides primitives to interact with the openapi HTTP API.
Package appointments provides primitives to interact with the openapi HTTP API.
generated/carrierpickup
Package carrierpickup provides primitives to interact with the openapi HTTP API.
Package carrierpickup provides primitives to interact with the openapi HTTP API.
generated/containers
Package containers provides primitives to interact with the openapi HTTP API.
Package containers provides primitives to interact with the openapi HTTP API.
generated/internationallabels
Package internationallabels provides primitives to interact with the openapi HTTP API.
Package internationallabels provides primitives to interact with the openapi HTTP API.
generated/internationalprices
Package internationalprices provides primitives to interact with the openapi HTTP API.
Package internationalprices provides primitives to interact with the openapi HTTP API.
generated/labels
Package labels provides primitives to interact with the openapi HTTP API.
Package labels provides primitives to interact with the openapi HTTP API.
generated/locations
Package locations provides primitives to interact with the openapi HTTP API.
Package locations provides primitives to interact with the openapi HTTP API.
generated/oauth2
Package oauth2 provides primitives to interact with the openapi HTTP API.
Package oauth2 provides primitives to interact with the openapi HTTP API.
generated/payments
Package payments provides primitives to interact with the openapi HTTP API.
Package payments provides primitives to interact with the openapi HTTP API.
generated/prices
Package prices provides primitives to interact with the openapi HTTP API.
Package prices provides primitives to interact with the openapi HTTP API.
generated/servicestandards
Package servicestandards provides primitives to interact with the openapi HTTP API.
Package servicestandards provides primitives to interact with the openapi HTTP API.
generated/servicestandardsfiles
Package servicestandardsfiles provides primitives to interact with the openapi HTTP API.
Package servicestandardsfiles provides primitives to interact with the openapi HTTP API.
generated/shipenrollment
Package shipenrollment provides primitives to interact with the openapi HTTP API.
Package shipenrollment provides primitives to interact with the openapi HTTP API.
generated/shipmenttracking
Package shipmenttracking provides primitives to interact with the openapi HTTP API.
Package shipmenttracking provides primitives to interact with the openapi HTTP API.
generated/shippingoptions
Package shippingoptions provides primitives to interact with the openapi HTTP API.
Package shippingoptions provides primitives to interact with the openapi HTTP API.
generated/tracking
Package tracking provides primitives to interact with the openapi HTTP API.
Package tracking provides primitives to interact with the openapi HTTP API.
Package usps is an unofficial Go client for USPS REST APIs v3.
Package usps is an unofficial Go client for USPS REST APIs v3.

Jump to

Keyboard shortcuts

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