api

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ImagePublishedEvent = func(filepath, filename, imageID, variant string) *event.ImagePublished {
	return &event.ImagePublished{
		SrcPath:      filepath,
		DstPath:      path.Join(filepath, filename),
		ImageID:      imageID,
		ImageVariant: variant,
	}
}

ImagePublishedEvent returns an ImagePublished event for the provided path

View Source
var ImageUploadedEvent = func(imageID, uploadPath, filename string) *event.ImageUploaded {
	return &event.ImageUploaded{
		ImageID:  imageID,
		Path:     uploadPath,
		Filename: filename,
	}
}

ImageUploadedEvent returns an ImageUploaded event for the provided image ID and upload path

View Source
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{}) error

ReadJSONBody reads the bytes from the provided body, and marshals it to the provided model interface.

func WriteJSONBody added in v0.3.0

func WriteJSONBody(v interface{}, w http.ResponseWriter, httpStatus int) error

WriteJSONBody marshals the provided interface into json, and writes it to the response body.

Types

type API

type API struct {
	Router *mux.Router
	// contains filtered or unexported fields
}

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, builder *url.Builder) *API

Setup creates the API struct and its endpoints with corresponding handlers

func (*API) Close

func (*API) Close(ctx context.Context) error

Close is called during graceful shutdown to give the API an opportunity to perform any required disposal task

func (*API) CreateDownloadHandler added in v0.9.0

func (api *API) CreateDownloadHandler(w http.ResponseWriter, req *http.Request)

CreateDownloadHandler is a handler that adds a new download to an existing image

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) GetDownloadHandler added in v0.9.0

func (api *API) GetDownloadHandler(w http.ResponseWriter, req *http.Request)

GetDownloadHandler is a handler that returns an individual download variant

func (*API) GetDownloadsHandler added in v0.9.0

func (api *API) GetDownloadsHandler(w http.ResponseWriter, req *http.Request)

GetDownloadsHandler is a handler that returns all the download variant for an image

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) UpdateDownloadHandler added in v0.9.0

func (api *API) UpdateDownloadHandler(w http.ResponseWriter, req *http.Request)

UpdateDownloadHandler is a handler to update an image download variant

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)
	AcquireImageLock(ctx context.Context, id string) (lockID string, err error)
	UnlockImage(ctx context.Context, lockID string)
}

MongoServer defines the required methods from MongoDB

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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