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.
28 lines
619 B
Go
28 lines
619 B
Go
package registry
|
|
|
|
import (
|
|
"net/http"
|
|
"reflect"
|
|
"runtime"
|
|
|
|
"github.com/gorilla/handlers"
|
|
)
|
|
|
|
// functionName returns the name of the function fn.
|
|
func functionName(fn interface{}) string {
|
|
return runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
|
|
}
|
|
|
|
// resolveHandlerName attempts to resolve a nice, pretty name for the passed
|
|
// in handler.
|
|
func resolveHandlerName(method string, handler http.Handler) string {
|
|
switch v := handler.(type) {
|
|
case handlers.MethodHandler:
|
|
return functionName(v[method])
|
|
case http.HandlerFunc:
|
|
return functionName(v)
|
|
default:
|
|
return functionName(handler.ServeHTTP)
|
|
}
|
|
}
|