trucks

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrorOther is a generic error
	ErrorOther int = iota
	// ErrorDuplicate is returned when a duplicate truck is created
	ErrorDuplicate
	// ErrorNotFound is	returned when a truck is not found
	ErrorNotFound
	// ErrorValidation is returned when a truck is not valid or JSON parsing fails
	ErrorValidation
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// API includes the trucks service, we're not using DI here
	Service Service
	// Use composition and embedding to wrap & extend the API base
	api.Base
}

API is the main truck API

func (*API) AddRoutes

func (a *API) AddRoutes(router *mux.Router)

AddRoutes registers all application routes with the API

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error is an application specific error type which also provides an error code.

func (*Error) Error

func (e *Error) Error() string

type Service

type Service interface {
	FindNear(lat float64, long float64, radius int) ([]Truck, error)
}

Service provides truck operations

type Truck

type Truck struct {
	// The truck ID
	ID string `json:"id"`

	// The name of the truck
	Name string `json:"name"`

	// Descripton / long text
	Description string `json:"description"`

	// Latitude location
	Lat float64 `json:"lat"`

	// Longitude location
	Long float64 `json:"long"`

	// Address in human readable form
	Address string `json:"address"`
	// contains filtered or unexported fields
}

"Truck" is the main truck model, used for both requests and responses swagger:model truck

type TruckService

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

TruckService is implementation of the Service interface backed by a database

func NewService

func NewService(db data.Database) *TruckService

NewService returns a new instance of TruckService

func (*TruckService) FindNear

func (s *TruckService) FindNear(lat float64, long float64, radius int) ([]Truck, error)

FindNear returns a list of trucks near a given lat & long and within a radius

Jump to

Keyboard shortcuts

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