diff --git a/pkg/blobserver/registry.go b/pkg/blobserver/registry.go index ecdd1868d..e5b472736 100644 --- a/pkg/blobserver/registry.go +++ b/pkg/blobserver/registry.go @@ -17,6 +17,7 @@ limitations under the License. package blobserver import ( + "errors" "fmt" "net/http" "sync" @@ -24,14 +25,22 @@ import ( "camlistore.org/pkg/jsonconfig" ) +var ErrHandlerTypeNotFound = errors.New("requested handler type not loaded") + type Loader interface { GetStorage(prefix string) (Storage, error) - GetHandlerType(prefix string) string // or "" + GetHandlerType(prefix string) string // returns "" if unknown // Returns either a Storage or an http.Handler GetHandler(prefix string) (interface{}, error) - FindHandlerByTypeIfLoaded(htype string) (prefix string, handler interface{}, err error) + // FindHandlerByType finds a handler by its handlerType and + // returns its prefix and handler if it's loaded. If it's not + // loaded, the error will be ErrHandlerTypeNotFound. + // + // This is used by handler constructors to find siblings (such as the "ui" type handler) + // which might have more knowledge about the configuration for discovery, etc. + FindHandlerByType(handlerType string) (prefix string, handler interface{}, err error) // If we're loading configuration in response to a web request // (as we do with App Engine), then this returns a request and diff --git a/pkg/server/publish.go b/pkg/server/publish.go index caf93e99a..81ff3c6c0 100644 --- a/pkg/server/publish.go +++ b/pkg/server/publish.go @@ -160,7 +160,7 @@ func (ph *PublishHandler) serveDiscovery(rw http.ResponseWriter, req *http.Reque }) return } - _, handler, err := ph.bsLoader.FindHandlerByTypeIfLoaded("ui") + _, handler, err := ph.bsLoader.FindHandlerByType("ui") if err != nil { discoveryHelper(rw, req, map[string]interface{}{ "error": "no admin handler running", diff --git a/pkg/serverconfig/serverconfig.go b/pkg/serverconfig/serverconfig.go index c9d518ef9..9f7c441d9 100644 --- a/pkg/serverconfig/serverconfig.go +++ b/pkg/serverconfig/serverconfig.go @@ -159,13 +159,13 @@ func (hl *handlerLoader) GetRequestContext() (req *http.Request, ok bool) { return hl.context, hl.context != nil } -func (hl *handlerLoader) FindHandlerByTypeIfLoaded(htype string) (prefix string, handler interface{}, err error) { +func (hl *handlerLoader) FindHandlerByType(htype string) (prefix string, handler interface{}, err error) { for prefix, config := range hl.config { if config.htype == htype { return prefix, hl.handler[prefix], nil } } - return "", nil, os.ErrNotExist + return "", nil, blobserver.ErrHandlerTypeNotFound } func (hl *handlerLoader) setupAll() {