mirror of
https://github.com/distribution/distribution.git
synced 2025-09-02 07:25:25 +00:00
Add registry middleware access to storage drivers
Signed-off-by: David Wu <dwu7401@gmail.com>
This commit is contained in:
@@ -92,6 +92,16 @@ var tlsVersions = map[string]uint16{
|
||||
// this channel gets notified when process receives signal. It is global to ease unit testing
|
||||
var quit = make(chan os.Signal, 1)
|
||||
|
||||
// HandlerFunc defines an http middleware
|
||||
type HandlerFunc func(config *configuration.Configuration, handler http.Handler) http.Handler
|
||||
|
||||
var handlerMiddlewares []HandlerFunc
|
||||
|
||||
// RegisterHandler is used to register http middlewares to the registry service
|
||||
func RegisterHandler(handlerFunc HandlerFunc) {
|
||||
handlerMiddlewares = append(handlerMiddlewares, handlerFunc)
|
||||
}
|
||||
|
||||
// ServeCmd is a cobra command for running the registry.
|
||||
var ServeCmd = &cobra.Command{
|
||||
Use: "serve <config>",
|
||||
@@ -172,6 +182,10 @@ func NewRegistry(ctx context.Context, config *configuration.Configuration) (*Reg
|
||||
handler = gorhandlers.CombinedLoggingHandler(os.Stdout, handler)
|
||||
}
|
||||
|
||||
for _, applyHandlerMiddleware := range handlerMiddlewares {
|
||||
handler = applyHandlerMiddleware(config, handler)
|
||||
}
|
||||
|
||||
server := &http.Server{
|
||||
Handler: handler,
|
||||
}
|
||||
|
Reference in New Issue
Block a user