simulator

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestPostcodes []PostcodeRecord

TestPostcodes contains the active in-memory test postcodes.

Functions

func ListenAndServe

func ListenAndServe(addr string) error

ListenAndServe starts a live HTTP server listening on the specified network address.

func LoadDefaultPostcodes added in v0.1.1

func LoadDefaultPostcodes() error

LoadDefaultPostcodes resets TestPostcodes and indexes to the embedded official dataset.

func LoadFile added in v0.1.1

func LoadFile(path string) error

LoadFile reads test postcodes from a file path and updates the simulator.

func LoadJSON added in v0.1.1

func LoadJSON(data []byte) error

LoadJSON loads test postcodes from raw JSON bytes into the simulator.

func LoadReader added in v0.1.1

func LoadReader(r io.Reader) error

LoadReader reads test postcodes from an io.Reader and updates the simulator.

func LoadRecords added in v0.1.1

func LoadRecords(records []PostcodeRecord) error

LoadRecords sets the active records and rebuilds internal lookup indexes.

func NewHandler

func NewHandler() http.Handler

NewHandler constructs an http.Handler that precisely simulates api.postcode.gov.ng.

func NewServer

func NewServer() *httptest.Server

NewServer starts an in-memory httptest.Server simulating api.postcode.gov.ng.

func ResetSimulatedRateLimits

func ResetSimulatedRateLimits()

ResetSimulatedRateLimits clears all recorded transient rate-limit counters in the simulator.

Types

type PostcodeRecord

type PostcodeRecord struct {
	Canonical    string  `json:"canonical"`
	StateCode    string  `json:"state_code"`
	StateName    string  `json:"state_name"`
	LGACode      string  `json:"lga_code"`
	LGAName      string  `json:"lga_name"`
	DistrictCode string  `json:"district_code"`
	DistrictName string  `json:"district_name"`
	AreaCode     string  `json:"area_code"`
	AreaName     string  `json:"area_name"`
	UnitCode     string  `json:"unit_code"`
	Zone         string  `json:"zone"`
	RecentHouse  string  `json:"recent_house"`
	BuildingUse  string  `json:"building_use"`
	Lat          float64 `json:"latitude"`
	Lng          float64 `json:"longitude"`
}

PostcodeRecord stores test metadata for an official test postcode.

func (*PostcodeRecord) UnmarshalJSON added in v0.1.1

func (p *PostcodeRecord) UnmarshalJSON(data []byte) error

UnmarshalJSON supports both "latitude"/"longitude" and "lat"/"lng" field names.

Jump to

Keyboard shortcuts

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