Documentation ¶
Overview ¶
Package api provides API endpoints and controllers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadRequest = etre.Error{ Type: "bad-request", HTTPStatus: http.StatusBadRequest, Message: "bad request", }
var ErrCDCDisabled = etre.Error{ Type: "cdc-disabled", HTTPStatus: http.StatusNotImplemented, Message: "CDC disabled", }
var ErrDb = etre.Error{ Type: "db-error", HTTPStatus: http.StatusInternalServerError, Message: "internal server error", }
var ErrDuplicateEntity = etre.Error{ Type: "dupe-entity", HTTPStatus: http.StatusConflict, Message: "duplicate entity", }
var ErrInternal = etre.Error{ Type: "internal-error", HTTPStatus: http.StatusInternalServerError, Message: "internal server error", }
var ErrInvalidParam = etre.Error{ Type: "invalid-param", HTTPStatus: http.StatusBadRequest, Message: "missing parameter", }
var ErrInvalidQuery = etre.Error{ Type: "invalid-query", HTTPStatus: http.StatusBadRequest, Message: "invalid query", }
var ErrMissingParam = etre.Error{ Type: "missing-param", HTTPStatus: http.StatusBadRequest, Message: "missing parameter", }
var ErrNotFound = etre.Error{ Type: "entity-not-found", HTTPStatus: http.StatusNotFound, Message: "entity not found", }
Functions ¶
func ConvertFloat64ToInt ¶
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 (*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.