rename FindHandlerByTypeIfLoaded to be shorter. document better.

Change-Id: I20b1a191d2d67972ba1f7a7fd3678d4ab4adae55
This commit is contained in:
Brad Fitzpatrick 2012-05-14 03:48:51 +10:00
parent 0f90f864f6
commit d29cbb5e35
3 changed files with 14 additions and 5 deletions

View File

@ -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

View File

@ -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",

View File

@ -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() {