Documentation ¶
Index ¶
- Variables
- func DeleteEntityHandler(ctx *gin.Context)
- func GetEntitiesHandler(ctx *gin.Context)
- func GetEntityHandler(ctx *gin.Context)
- func HealthCheckHandler(ctx *gin.Context)
- func RegisterEntityHandler(ctx *gin.Context)
- func RegisterLocationHandler(ctx *gin.Context)
- type Entity
- type GeoLocation
- type Persistence
- func (db *Persistence) DeleteEntity(entityId uuid.UUID) error
- func (db *Persistence) GetEntities() ([]Entity, error)
- func (db *Persistence) GetEntity(entityId uuid.UUID) (Entity, error)
- func (db *Persistence) RegisterEntity(meta map[string]interface{}) error
- func (db *Persistence) SetEntityLocation(entityId uuid.UUID, location GeoLocation) error
Constants ¶
This section is empty.
Variables ¶
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", } "http_code": http.StatusUnauthorized, "message": "Unauthorized", } NotImplementedResponse = gin.H{ "http_code": http.StatusNotImplemented, "message": "Not Implemented", } )
var ( // define custom errors ErrEntityNotFound = errors.New("cannot find entity with provided entity ID") ErrInvalidEntityMeta = errors.New("entity has invalid metadata") )
Functions ¶
func DeleteEntityHandler ¶
API handler used to delete a given entity
func GetEntitiesHandler ¶
API handler used to retrieve list of current entities
func GetEntityHandler ¶
API handler used to retreive location for a given entity
func HealthCheckHandler ¶
API handler used to serve health check request
func RegisterEntityHandler ¶
API handler used to register new entity
func RegisterLocationHandler ¶
API handler used to register new location for a given entity
Types ¶
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