api

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

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogSeverityInfo int = iota
	LogSeveritySuccess
	LogSeverityWarning
	LogSeverityDanger
)
View Source
const VideoDeathFrequency = time.Second

VideoDeathFrequency is the frequency of which we send the "dead"

View Source
const VideoDeathThreshold = time.Second * 5

VideoDeathThreshold is the duration we wait before we show the "dead" image

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(c *gin.Context, msg string)

Types

type API

type API struct {
	Config *config.Config
	Log    *logrus.Logger
	Gin    *gin.Engine
	DB     *sqlx.DB
	Bucket *blob.Bucket

	Server *http.Server
	// contains filtered or unexported fields
}

API contains all the dependencies of the API server

func NewAPI

func NewAPI(
	conf *config.Config,
	log *logrus.Logger,
	db *sqlx.DB,
	bucket *blob.Bucket,
) *API

NewAPI sets up a new API module.

func (*API) AuthChgPassPost

func (a *API) AuthChgPassPost(c *gin.Context)

func (*API) AuthForgotPost

func (a *API) AuthForgotPost(c *gin.Context)

func (*API) AuthRegisterPost

func (a *API) AuthRegisterPost(c *gin.Context)

AuthRegisterPost takes: - forename - surname - email address - password (in plaintext)

Usually returns:

  • HTTP Status OK (200) At this point the user should receive a verification token in their inbox. This will be done later.

Otherwise, complains about: - Bad email format - Email address already existing - Shitty password (min 8 characters please)

func (*API) EventCheck

func (a *API) EventCheck(c *gin.Context)

EventCheck is a middleware to check whether the passed event id exists, and (if logged in) confirms whether the currently logged in user owns that event

func (*API) EventCreatePost

func (a *API) EventCreatePost(c *gin.Context)

EventCreatePost gets the plant object

func (*API) EventDelete

func (a *API) EventDelete(c *gin.Context)

EventDelete gets the plant object

func (*API) EventGet

func (a *API) EventGet(c *gin.Context)

EventGet gets the Event object

func (*API) EventListGet

func (a *API) EventListGet(c *gin.Context)

EventListGet gets the plant object

func (*API) EventPut

func (a *API) EventPut(c *gin.Context)

EventPut updates the event object

func (*API) GetStream

func (a *API) GetStream(rid uuid.UUID) *Stream

func (*API) LogCheck

func (a *API) LogCheck(c *gin.Context)

LogCheck is a middleware to check whether the passed entry id exists, and (if logged in) confirms whether the currently logged in user owns that entry

func (*API) LogEntryDelete

func (a *API) LogEntryDelete(c *gin.Context)

func (*API) LogListGet

func (a *API) LogListGet(c *gin.Context)

LogListGet returns a list of log entries

func (*API) NotImplemented

func (a *API) NotImplemented(c *gin.Context)

func (*API) PhotoCheck

func (a *API) PhotoCheck(c *gin.Context)

PhotoCheck is a middleware to check whether the passed photo uuid exists, and (if logged in) confirms whether the currently logged in user owns that robot

func (*API) PhotoDelete

func (a *API) PhotoDelete(c *gin.Context)

PhotoDelete deletes the associated photo

func (*API) PhotoServeGet

func (a *API) PhotoServeGet(c *gin.Context)

PhotoServeGet serves the associated photo

func (*API) PhotosListGet

func (a *API) PhotosListGet(c *gin.Context)

PhotosListGet requires you to be logged in. It lists all photos of plants the user owns

func (*API) PlantCheck

func (a *API) PlantCheck(c *gin.Context)

PlantCheck is a middleware to check whether the passed plant uuid exists, and (if logged in) confirms whether the currently logged in user owns that plant

func (*API) PlantCreatePost

func (a *API) PlantCreatePost(c *gin.Context)

PlantCreatePost gets the plant object

func (*API) PlantDelete

func (a *API) PlantDelete(c *gin.Context)

PlantDelete deletes the plant object

func (*API) PlantGet

func (a *API) PlantGet(c *gin.Context)

PlantGet gets the plant object

func (*API) PlantListGet

func (a *API) PlantListGet(c *gin.Context)

PlantListGet requires you to be logged in. It lists all plants the user owns

func (*API) PlantRenamePatch

func (a *API) PlantRenamePatch(c *gin.Context)

PlantRenamePatch gets the plant object

func (*API) RobotCheck

func (a *API) RobotCheck(c *gin.Context)

RobotCheck is a middleware to check whether the passed robot uuid exists, and (if logged in) confirms whether the currently logged in user owns that robot

func (*API) RobotDelete

func (a *API) RobotDelete(c *gin.Context)

RobotDelete disassociates the robot from the current user

func (*API) RobotListGet

func (a *API) RobotListGet(c *gin.Context)

RobotListGet requires you to be logged in. It lists all robots the user owns + the robot state.

func (*API) RobotMovePost

func (a *API) RobotMovePost(c *gin.Context)

func (*API) RobotRegisterPost

func (a *API) RobotRegisterPost(c *gin.Context)

RobotRegisterPost takes a "robot_id" in the JSON body. It registers the robot corresponding to the UUID to the currently logged in user.

Usually returns HTTP Status OK. Otherwise complains.

func (*API) RobotSetStandby

func (a *API) RobotSetStandby(c *gin.Context)

func (*API) RobotSettingsPatch

func (a *API) RobotSettingsPatch(c *gin.Context)

func (*API) RobotStartDemoPost

func (a *API) RobotStartDemoPost(c *gin.Context)

func (*API) RobotStatusGet

func (a *API) RobotStatusGet(c *gin.Context)

RobotStatusGet returns the state of the robot + whether or not it is currently connected

func (*API) RobotVideoGet

func (a *API) RobotVideoGet(c *gin.Context)

RobotVideoGet streams the video

func (*API) Shutdown

func (a *API) Shutdown(ctx context.Context) error

Shutdown shuts down the API

func (*API) Start

func (a *API) Start() error

Start binds the API and starts listening.

func (*API) StreamRobot

func (a *API) StreamRobot(ctx *gin.Context)

func (*API) StreamRobotVideo

func (a *API) StreamRobotVideo(ctx *gin.Context)

func (*API) StreamUser

func (a *API) StreamUser(ctx *gin.Context)

type LogEntry

type LogEntry struct {
	ID        int        `json:"id" db:"id"`
	UserID    int        `json:"user_id" db:"user_id"`
	Type      string     `json:"type" db:"type"`
	Message   string     `json:"message" db:"message"`
	Severity  int        `json:"severity" db:"severity"`
	RobotID   *uuid.UUID `json:"robot_id,omitempty" db:"robot_id"`
	PlantID   *int       `json:"plant_id,omitempty" db:"plant_id"`
	CreatedAt time.Time  `json:"created_at" db:"created_at"`
}

type Stream

type Stream struct {
	Inner      *mjpeg.Stream
	LastUpdate time.Time
}

func (*Stream) Update

func (s *Stream) Update(b []byte) error

Jump to

Keyboard shortcuts

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