vpic

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package vpic is the library behind the vpic command line: the HTTP client, request shaping, and the typed data models for the NHTSA Vehicle Product Information Catalog (VPIC) API.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load. Build your endpoint calls and JSON decoding on top of it.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "vpic-cli/dev (+https://github.com/tamnd/vpic-cli)"

DefaultUserAgent identifies the client to VPIC.

View Source
const Host = "vpic.nhtsa.dot.gov"

Host is the NHTSA VPIC API host.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to the NHTSA VPIC API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: a 30s timeout, a 300ms minimum gap between requests, and five retries on transient errors.

func (*Client) DecodeVIN

func (c *Client) DecodeVIN(ctx context.Context, vin string) (*VINDecode, error)

DecodeVIN decodes a VIN number and returns the key fields. ErrorCode "0" = success, "6" = invalid VIN, "8" = check-digit mismatch (usable), "11" = incomplete VIN (returns error).

func (*Client) GetModels

func (c *Client) GetModels(ctx context.Context, make string, year int) ([]Model, error)

GetModels returns models for a given make and model year.

func (*Client) GetVehicleTypes

func (c *Client) GetVehicleTypes(ctx context.Context, make string) ([]VehicleType, error)

GetVehicleTypes returns vehicle types for a given make.

func (*Client) ListMakes

func (c *Client) ListMakes(ctx context.Context, limit int) ([]Make, error)

ListMakes returns all vehicle makes, truncated to limit (0 = no limit).

type Domain

type Domain struct{}

Domain is the VPIC driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Make

type Make struct {
	ID   int    `kit:"id" json:"make_id"`
	Name string `json:"make_name"`
}

Make is a vehicle manufacturer.

type Model

type Model struct {
	MakeID   int    `json:"make_id"`
	MakeName string `json:"make_name"`
	ModelID  int    `kit:"id" json:"model_id"`
	Name     string `json:"model_name"`
}

Model is a vehicle model for a given make and year.

type VINDecode

type VINDecode struct {
	VIN             string `kit:"id" json:"vin"`
	Make            string `json:"make"`
	Model           string `json:"model"`
	ModelYear       string `json:"model_year"`
	BodyClass       string `json:"body_class"`
	VehicleType     string `json:"vehicle_type"`
	DriveType       string `json:"drive_type"`
	FuelTypePrimary string `json:"fuel_type_primary"`
	EngineHP        string `json:"engine_hp"`
	EngineModel     string `json:"engine_model"`
	Displacement    string `json:"displacement_l"`
	PlantCity       string `json:"plant_city"`
	PlantCountry    string `json:"plant_country"`
}

VINDecode holds the decoded fields from a VIN lookup.

type VehicleType

type VehicleType struct {
	ID   int    `kit:"id" json:"type_id"`
	Name string `json:"type_name"`
}

VehicleType is a vehicle type for a given make.

Jump to

Keyboard shortcuts

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