api

package
v0.0.0-...-b0b986f Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(srv *http.Server) error

ListenAndServe starts the server and blocks until shutdown signal.

func NewServer

func NewServer(cfg ServerConfig, handlers *Handlers) *http.Server

NewServer creates an HTTP server with all routes and middleware.

Types

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
	Field string `json:"field,omitempty"`
}

ErrorResponse is the JSON response for errors.

type Handlers

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

Handlers holds the HTTP handlers and their dependencies.

func NewHandlers

func NewHandlers(router routing.Router, stats StatsResponse) *Handlers

NewHandlers creates handlers with the given router.

func (*Handlers) HandleHealth

func (h *Handlers) HandleHealth(w http.ResponseWriter, r *http.Request)

HandleHealth handles GET /api/v1/health.

func (*Handlers) HandleRoute

func (h *Handlers) HandleRoute(w http.ResponseWriter, r *http.Request)

HandleRoute handles POST /api/v1/route.

func (*Handlers) HandleStats

func (h *Handlers) HandleStats(w http.ResponseWriter, r *http.Request)

HandleStats handles GET /api/v1/stats.

type HealthResponse

type HealthResponse struct {
	Status string `json:"status"`
}

HealthResponse is the JSON response for GET /api/v1/health.

type LatLngJSON

type LatLngJSON struct {
	Lat float64 `json:"lat"`
	Lng float64 `json:"lng"`
}

LatLngJSON represents a lat/lng pair in JSON.

type RouteRequest

type RouteRequest struct {
	Start LatLngJSON `json:"start"`
	End   LatLngJSON `json:"end"`
}

RouteRequest is the JSON body for POST /api/v1/route.

type RouteResponse

type RouteResponse struct {
	TotalDistanceMeters float64       `json:"total_distance_meters"`
	Segments            []SegmentJSON `json:"segments"`
}

RouteResponse is the JSON response for a successful route query.

type SegmentJSON

type SegmentJSON struct {
	DistanceMeters float64      `json:"distance_meters"`
	Geometry       []LatLngJSON `json:"geometry"`
}

SegmentJSON represents a road segment in the response.

type ServerConfig

type ServerConfig struct {
	Addr          string
	ReadTimeout   time.Duration
	WriteTimeout  time.Duration
	MaxConcurrent int
	CORSOrigin    string
}

ServerConfig holds server configuration.

func DefaultConfig

func DefaultConfig(addr string) ServerConfig

DefaultConfig returns sensible defaults.

type StatsResponse

type StatsResponse struct {
	NumNodes    uint32 `json:"num_nodes"`
	NumFwdEdges int    `json:"num_fwd_edges"`
	NumBwdEdges int    `json:"num_bwd_edges"`
}

StatsResponse is the JSON response for GET /api/v1/stats.

Jump to

Keyboard shortcuts

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