api

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NewID generates a random uuid and returns it as a string.
	NewID = func() string {
		return uuid.NewV4().String()
	}
)

Functions

func ReadJSONBody added in v0.9.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.

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(router *mux.Router, dataStore DataStorer, permissions AuthHandler, taskNames map[string]bool, cfg *config.Config, httpClient dpHTTP.Clienter, reindex Indexer) *API

Setup function sets up the api and returns an api

func (*API) Close added in v0.10.0

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) CreateJobHandler added in v0.10.0

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

CreateJobHandler generates a new Job resource and a new ElasticSearch index associated with it .

func (*API) CreateTaskHandler added in v0.10.0

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

CreateTaskHandler returns a function that generates a new TaskName resource containing default values in its fields.

func (*API) GetJobHandler added in v0.10.0

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

GetJobHandler returns a function that gets an existing Job resource, from the Job Store, that's associated with the id passed in.

func (*API) GetJobsHandler added in v0.10.0

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

GetJobsHandler gets a list of existing Job resources, from the Job Store, sorted by their values of last_updated time (ascending).

func (*API) GetTaskHandler added in v0.10.0

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

GetTaskHandler returns a function that gets a specific task, associated with an existing Job resource, using the job id and task name passed in.

func (*API) GetTasksHandler added in v0.12.0

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

GetTasksHandler gets a list of existing Task resources, from the data store, sorted by their values of last_updated time (ascending).

func (*API) PutNumTasksHandler added in v0.10.0

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

PutNumTasksHandler returns a function that updates the number_of_tasks in an existing Job resource, which is associated with the id passed in.

type AuthHandler added in v0.9.0

type AuthHandler interface {
	Require(required auth.Permissions, handler http.HandlerFunc) http.HandlerFunc
}

AuthHandler provides authorisation checks on requests

type DataStorer added in v0.10.0

type DataStorer interface {
	CreateJob(ctx context.Context, id string) (job models.Job, err error)
	GetJob(ctx context.Context, id string) (job models.Job, err error)
	GetJobs(ctx context.Context, offset int, limit int) (job models.Jobs, err error)
	AcquireJobLock(ctx context.Context, id string) (lockID string, err error)
	UnlockJob(lockID string) error
	PutNumberOfTasks(ctx context.Context, id string, count int) error
	CreateTask(ctx context.Context, jobID string, taskName string, numDocuments int) (task models.Task, err error)
	GetTask(ctx context.Context, jobID string, taskName string) (task models.Task, err error)
	GetTasks(ctx context.Context, offset int, limit int, jobID string) (job models.Tasks, err error)
	UpdateIndexName(indexName string, jobID string) error
	UpdateJobState(state string, jobID string) error
}

DataStorer is an interface for a type that can store and retrieve jobs

type Indexer added in v0.14.0

type Indexer interface {
	CreateIndex(ctx context.Context, serviceAuthToken, searchAPISearchURL string, httpClient dpHTTP.Clienter) (*http.Response, error)
	GetIndexNameFromResponse(ctx context.Context, body io.ReadCloser) (string, error)
}

type Paginator added in v0.8.0

type Paginator interface {
	ValidatePaginationParameters(offsetParam string, limitParam string, totalCount int) (offset int, limit int, err error)
}

Paginator defines the required methods from the paginator package

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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