Documentation
¶
Index ¶
- Variables
- func ReadJSONBody(ctx context.Context, body io.ReadCloser, v interface{}, w http.ResponseWriter, ...) error
- func WriteJSONBody(ctx context.Context, v interface{}, w http.ResponseWriter, data log.Data) error
- type API
- func (*API) Close(ctx context.Context) error
- func (api *API) CreateImageHandler(w http.ResponseWriter, req *http.Request)
- func (api *API) GetImageHandler(w http.ResponseWriter, req *http.Request)
- func (api *API) GetImagesHandler(w http.ResponseWriter, req *http.Request)
- func (api *API) PublishImageHandler(w http.ResponseWriter, req *http.Request)
- func (api *API) UpdateImageHandler(w http.ResponseWriter, req *http.Request)
- type AuthHandler
- type MongoServer
Constants ¶
This section is empty.
Variables ¶
var NewID = func() string { return uuid.NewV4().String() }
NewID returns a new UUID
Functions ¶
func ReadJSONBody ¶ added in v0.3.0
func ReadJSONBody(ctx context.Context, body io.ReadCloser, v interface{}, w http.ResponseWriter, data log.Data) error
ReadJSONBody reads the bytes from the provided body, and marshals it to the provided model interface.
func WriteJSONBody ¶ added in v0.3.0
WriteJSONBody marshals the provided interface into json, and writes it to the response body.
Types ¶
type API ¶
API provides a struct to wrap the api around
func Setup ¶
func Setup(ctx context.Context, cfg *config.Config, r *mux.Router, auth AuthHandler, mongoDB MongoServer, uploadedKafkaProducer, publishedKafkaProducer kafka.IProducer) *API
Setup creates the API struct and its endpoints with corresponding handlers
func (*API) Close ¶
Close is called during graceful shutdown to give the API an opportunity to perform any required disposal task
func (*API) CreateImageHandler ¶ added in v0.3.0
func (api *API) CreateImageHandler(w http.ResponseWriter, req *http.Request)
CreateImageHandler is a handler that inserts an image into mongoDB with a newly generated ID
func (*API) GetImageHandler ¶ added in v0.3.0
func (api *API) GetImageHandler(w http.ResponseWriter, req *http.Request)
GetImageHandler is a handler that gets an image by its id from MongoDB
func (*API) GetImagesHandler ¶ added in v0.3.0
func (api *API) GetImagesHandler(w http.ResponseWriter, req *http.Request)
GetImagesHandler is a handler that gets all images in a collection from MongoDB
func (*API) PublishImageHandler ¶ added in v0.3.0
func (api *API) PublishImageHandler(w http.ResponseWriter, req *http.Request)
PublishImageHandler is a handler that triggers the publishing of an image
func (*API) UpdateImageHandler ¶ added in v0.3.0
func (api *API) UpdateImageHandler(w http.ResponseWriter, req *http.Request)
UpdateImageHandler is a handler that updates an existing image in MongoDB
type AuthHandler ¶ added in v0.3.0
type AuthHandler interface {
Require(required dpauth.Permissions, handler http.HandlerFunc) http.HandlerFunc
}
AuthHandler interface for adding auth to endpoints
type MongoServer ¶ added in v0.3.0
type MongoServer interface { Close(ctx context.Context) error Checker(ctx context.Context, state *healthcheck.CheckState) (err error) GetImages(ctx context.Context, collectionID string) (images []models.Image, err error) GetImage(ctx context.Context, id string) (image *models.Image, err error) UpdateImage(ctx context.Context, id string, image *models.Image) (didChange bool, err error) UpsertImage(ctx context.Context, id string, image *models.Image) (err error) }
MongoServer defines the required methods from MongoDB