api

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// define common responses and structs for REST
	// interfaces and responses
	InternalServerErrorResponse = gin.H{
		"http_code": http.StatusInternalServerError,
		"message":   "Internal server error",
	}
	InvalidRequestBodyResponse = gin.H{
		"http_code": http.StatusBadRequest,
		"message":   "Invalid request body",
	}
	ForbiddenResponse = gin.H{
		"http_code": http.StatusForbidden,
		"message":   "Forbidden",
	}
	UnauthorizedResponse = gin.H{
		"http_code": http.StatusUnauthorized,
		"message":   "Unauthorized",
	}
	NotImplementedResponse = gin.H{
		"http_code": http.StatusNotImplemented,
		"message":   "Not Implemented",
	}
)
View Source
var (
	// define custom errors
	ErrEntityNotFound    = errors.New("cannot find entity with provided entity ID")
	ErrInvalidEntityMeta = errors.New("entity has invalid metadata")
)

Functions

func DeleteEntityHandler

func DeleteEntityHandler(ctx *gin.Context)

API handler used to delete a given entity

func GetEntitiesHandler

func GetEntitiesHandler(ctx *gin.Context)

API handler used to retrieve list of current entities

func GetEntityHandler

func GetEntityHandler(ctx *gin.Context)

API handler used to retreive location for a given entity

func HealthCheckHandler

func HealthCheckHandler(ctx *gin.Context)

API handler used to serve health check request

func RegisterEntityHandler

func RegisterEntityHandler(ctx *gin.Context)

API handler used to register new entity

func RegisterLocationHandler

func RegisterLocationHandler(ctx *gin.Context)

API handler used to register new location for a given entity

Types

type Entity

type Entity struct {
	EntityId    uuid.UUID              `json:"entity_id"`
	LastUpdated *time.Time             `json:"last_updated"`
	Location    *GeoLocation           `json:"location"`
	Meta        map[string]interface{} `json:"meta"`
}

type GeoLocation

type GeoLocation struct {
	Latitude  float64 `json:"latitude" binding:"required"`
	Longitude float64 `json:"longitude" binding:"required"`
}

func (GeoLocation) IsValid

func (l GeoLocation) IsValid() bool

set function on GeoLocation instance to check for validity

type Persistence

type Persistence struct {
	*utils.PostgresPersistence
}

func NewPersistence

func NewPersistence(host string, port int, username,
	password, database string) *Persistence

function used to generate new persistence instance to retrieve and manage data

func SetPersistence

func SetPersistence(host string, port int, username,
	password, database string) *Persistence

function used to set global persistence layer

func (*Persistence) DeleteEntity

func (db *Persistence) DeleteEntity(entityId uuid.UUID) error

function used to delete a given entity

func (*Persistence) GetEntities

func (db *Persistence) GetEntities() ([]Entity, error)

function to retrieve all entities from the postgres database

func (*Persistence) GetEntity

func (db *Persistence) GetEntity(entityId uuid.UUID) (Entity, error)

function to retrieve single entity from the postgres database

func (*Persistence) RegisterEntity

func (db *Persistence) RegisterEntity(meta map[string]interface{}) error

function to add new entity to the postgres database

func (*Persistence) SetEntityLocation

func (db *Persistence) SetEntityLocation(entityId uuid.UUID,
	location GeoLocation) error

function used to set location for a given entity

Jump to

Keyboard shortcuts

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