ukpolice

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: 9 Imported by: 0

Documentation

Overview

Package ukpolice is the library behind the ukpolice command line: the HTTP client, request shaping, and the typed data models for the UK Police Data API (https://data.police.uk/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.

Index

Constants

View Source
const Host = "data.police.uk"

Host is the API host.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the UK Police Data API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client using DefaultConfig.

func NewClientWithConfig

func NewClientWithConfig(cfg Config) *Client

NewClientWithConfig returns a Client with the given Config.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the base URL for the client.

func (*Client) Categories

func (c *Client) Categories(ctx context.Context, date string) ([]*CrimeCategory, error)

Categories returns the list of crime categories for a given YYYY-MM date. If date is empty the API uses its latest available month.

func (*Client) Crimes

func (c *Client) Crimes(ctx context.Context, lat, lng, date, category string) ([]*Crime, error)

Crimes returns street-level crimes near the given latitude/longitude for the given YYYY-MM date and crime category (use "all-crime" for all categories). If date is empty the API uses its latest available month.

func (*Client) Force

func (c *Client) Force(ctx context.Context, forceID string) (*ForceDetail, error)

Force returns the details of a single police force by its ID.

func (*Client) Forces

func (c *Client) Forces(ctx context.Context) ([]*Force, error)

Forces returns all UK police forces.

func (*Client) StopSearches

func (c *Client) StopSearches(ctx context.Context, forceID, date string) ([]*StopSearch, error)

StopSearches returns stop-and-search records for a force for the given YYYY-MM date. If date is empty the API uses its latest available month.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds the client configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the UK Police Data API client.

type Crime

type Crime struct {
	ID            string         `json:"persistent_id"   kit:"id"`
	Category      string         `json:"category"`
	Month         string         `json:"month"`
	Location      *CrimeLocation `json:"location"`
	LocationType  string         `json:"location_type,omitempty"`
	Context       string         `json:"context,omitempty"`
	OutcomeStatus *OutcomeStatus `json:"outcome_status"`
}

Crime is a single street-level crime record.

type CrimeCategory

type CrimeCategory struct {
	URL  string `json:"url"  kit:"id"`
	Name string `json:"name" kit:"title"`
}

CrimeCategory is a crime classification returned by /crime-categories.

type CrimeLocation

type CrimeLocation struct {
	Latitude  string  `json:"latitude"`
	Longitude string  `json:"longitude"`
	Street    *Street `json:"street"`
}

CrimeLocation is the approximate location of a crime.

type Domain

type Domain struct{}

Domain is the ukpolice 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 EngagementMethod

type EngagementMethod struct {
	URL         string `json:"url,omitempty"`
	Type        string `json:"type"`
	Description string `json:"description,omitempty"`
	Title       string `json:"title,omitempty"`
}

EngagementMethod is a contact / social-media channel for a force.

type Force

type Force struct {
	ID   string `json:"id"   kit:"id"`
	Name string `json:"name" kit:"title"`
}

Force is a summary of a single UK police force.

type ForceDetail

type ForceDetail struct {
	ID                string             `json:"id"                          kit:"id"`
	Name              string             `json:"name"                        kit:"title"`
	Description       string             `json:"description,omitempty"       kit:"body"`
	URL               string             `json:"url,omitempty"`
	Telephone         string             `json:"telephone,omitempty"`
	EngagementMethods []EngagementMethod `json:"engagement_methods,omitempty"`
}

ForceDetail is the full detail for a single UK police force.

type OutcomeStatus

type OutcomeStatus struct {
	Category string `json:"category"`
	Date     string `json:"date"`
}

OutcomeStatus is the most recent recorded outcome of a crime.

type StopSearch

type StopSearch struct {
	Type                 string `json:"type"`
	DateTime             string `json:"datetime,omitempty"`
	Outcome              string `json:"outcome,omitempty"`
	ObjectOfSearch       string `json:"object_of_search,omitempty"`
	AgeRange             string `json:"age_range,omitempty"`
	Gender               string `json:"gender,omitempty"`
	SelfDefinedEthnicity string `json:"self_defined_ethnicity,omitempty"`
}

StopSearch is a single stop-and-search record.

type Street

type Street struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Street names the anonymised street a crime is recorded on.

Jump to

Keyboard shortcuts

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