api

package
v0.8.1-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package api provides API endpoints and controllers.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadRequest = etre.Error{
	Type:       "bad-request",
	HTTPStatus: http.StatusBadRequest,
	Message:    "bad request",
}
View Source
var ErrCDCDisabled = etre.Error{
	Type:       "cdc-disabled",
	HTTPStatus: http.StatusNotImplemented,
	Message:    "CDC disabled",
}
View Source
var ErrDb = etre.Error{
	Type:       "db-error",
	HTTPStatus: http.StatusInternalServerError,
	Message:    "internal server error",
}
View Source
var ErrDuplicateEntity = etre.Error{
	Type:       "dupe-entity",
	HTTPStatus: http.StatusConflict,
	Message:    "duplicate entity",
}
View Source
var ErrInternal = etre.Error{
	Type:       "internal-error",
	HTTPStatus: http.StatusInternalServerError,
	Message:    "internal server error",
}
View Source
var ErrInvalidParam = etre.Error{
	Type:       "invalid-param",
	HTTPStatus: http.StatusBadRequest,
	Message:    "missing parameter",
}
View Source
var ErrInvalidQuery = etre.Error{
	Type:       "invalid-query",
	HTTPStatus: http.StatusBadRequest,
	Message:    "invalid query",
}
View Source
var ErrMissingParam = etre.Error{
	Type:       "missing-param",
	HTTPStatus: http.StatusBadRequest,
	Message:    "missing parameter",
}
View Source
var ErrNotFound = etre.Error{
	Type:       "entity-not-found",
	HTTPStatus: http.StatusNotFound,
	Message:    "entity not found",
}

Functions

func ConvertFloat64ToInt

func ConvertFloat64ToInt(entity etre.Entity)

JSON treats all numbers as floats. Given this, when we see a float with decimal values of all 0, it is unclear if the user passed in 3.0 (type float) or 3 (type int). So, since we cannot tell the difference between a some float numbers and integer numbers, we cast all floats to ints. This means that floats with non-zero decimal values, such as 3.14 (type float), will get truncated to 3i (type int) in this case.

Types

type API

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

API provides controllers for endpoints it registers with a router.

func NewAPI

func NewAPI(addr string, es entity.Store, ff cdc.FeedFactory) *API

NewAPI makes a new API.

func (*API) Router

func (api *API) Router() *echo.Echo

func (*API) ServeHTTP

func (api *API) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP allows the API to statisfy the http.HandlerFunc interface.

func (*API) Use

func (api *API) Use(middleware ...echo.MiddlewareFunc)

Use adds middleware to the echo web server in the API. See https://echo.labstack.com/middleware for more details.

func (*API) WriteResults

func (api *API) WriteResults(v interface{}, err error) []etre.WriteResult

WriteResults makes a slice of etre.WriteResult for each item in v, which is either []string{<ids>} on POST/create or []etre.Entity{} on PUT/update and DELETE/delete. If err is not nil, it's the first (last and only) error on write which applies to the last WriteResult in the returned slice. The caller must handle this case:

if v == nil && err != nil {

In that case, no writes were attempted, presumably because of a low-level db issue (e.g. db is offiline). In other words: v most not be nil.

Jump to

Keyboard shortcuts

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