mirror of
https://github.com/distribution/distribution
synced 2024-11-12 05:45:51 +01:00
22c9f45598
This changeset defines the application structure to be used for the http side of the new registry. The main components are the App and Context structs. The App context is instance global and manages global configuration and resources. Context contains request-specific resources that may be created as a by-product of an in-flight request. To latently construct per-request handlers and leverage gorilla/mux, a dispatch structure has been propped up next to the main handler flow. Without this, a router and all handlers need to be constructed on every request. By constructing handlers on each request, we ensure thread isolation and can carefully control the security context of in-flight requests. There are unit tests covering this functionality.
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package registry
|
|
|
|
import (
|
|
"github.com/Sirupsen/logrus"
|
|
)
|
|
|
|
// Context should contain the request specific context for use in across
|
|
// handlers. Resources that don't need to be shared across handlers should not
|
|
// be on this object.
|
|
type Context struct {
|
|
// App points to the application structure that created this context.
|
|
*App
|
|
|
|
// Name is the prefix for the current request. Corresponds to the
|
|
// namespace/repository associated with the image.
|
|
Name string
|
|
|
|
// Errors is a collection of errors encountered during the request to be
|
|
// returned to the client API. If errors are added to the collection, the
|
|
// handler *must not* start the response via http.ResponseWriter.
|
|
Errors Errors
|
|
|
|
// TODO(stevvooe): Context would be a good place to create a
|
|
// representation of the "authorized resource". Perhaps, rather than
|
|
// having fields like "name", the context should be a set of parameters
|
|
// then we do routing from there.
|
|
|
|
// vars contains the extracted gorilla/mux variables that can be used for
|
|
// assignment.
|
|
vars map[string]string
|
|
|
|
// log provides a context specific logger.
|
|
log *logrus.Entry
|
|
}
|