server

package
v0.0.0-...-4d2a565 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package state-server is the State Server REST API HTTP server. It uses the go-chi framework to handle http requests to get the state (or states) in which a location is contained, render the state location data as JSON in the [RFC 7946 GeoJSON] format, render the full collection of states, create a state, or delete a state.

Example requests

Get the state(s), if any, in which a location exists:

$ curl  -d "longitude=-77.036133&latitude=40.513799" http://localhost:8080/
["Pennsylvania"]

$ curl  -d "longitude=-77.036133&latitude=45" http://localhost:8080/
{"status":"Not Found","error":"[-77.036133, 45] not within any state"}

Get the GeoJSON Feature object which contains the location data for Pennsylvania

$ curl http://localhost:8080/api/v1/state/pennsylvania
"type":"Feature","properties":{"state":"Pennsylvania"},"geometry":{"type":"Polygon","coordinates":[[[-77.475793,39.719623],..., ]]}}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abort

func Abort(action Action, msg string)

func LoadConfig

func LoadConfig() (serverConfig, error)

func StateServerAPIRouter

func StateServerAPIRouter(store StateLocationDataProvider) *chi.Mux

Types

type Action

type Action string
const (
	Start    Action = "start"
	Shutdown Action = "shutdown"
)

type StateLocationDataProvider

type StateLocationDataProvider interface {
	GetAll() ([]geospatial.State, error)
	GetByName(name string) (geospatial.State, error)
	Create(geospatial.State) (geospatial.State, error)
	Delete(name string) error
}

type StateServer

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

func NewStateServer

func NewStateServer(config serverConfig, store StateLocationDataProvider) *StateServer

func (*StateServer) Start

func (s *StateServer) Start(ctx context.Context) error

Jump to

Keyboard shortcuts

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