mirror of https://github.com/perkeep/perkeep.git
importer: initialize Host's search handler and blobserver target
Change-Id: I482e6f192620c254648b19b3044eedbd44de288c
This commit is contained in:
parent
3f9887011f
commit
35e77c45ad
|
@ -64,6 +64,13 @@ type Loader interface {
|
|||
GetStorage(prefix string) (Storage, error)
|
||||
}
|
||||
|
||||
// HandlerIniter is an optional interface which can be implemented
|
||||
// by Storage or http.Handlers (from StorageConstructor or HandlerConstructor)
|
||||
// to be called once all the handlers have been created.
|
||||
type HandlerIniter interface {
|
||||
InitHandler(FindHandlerByTyper) error
|
||||
}
|
||||
|
||||
// A StorageConstructor returns a Storage implementation from a Loader
|
||||
// environment and a configuration.
|
||||
type StorageConstructor func(Loader, jsonconfig.Obj) (Storage, error)
|
||||
|
|
|
@ -29,15 +29,14 @@ import (
|
|||
"camlistore.org/pkg/blobserver"
|
||||
"camlistore.org/pkg/jsonconfig"
|
||||
"camlistore.org/pkg/search"
|
||||
"camlistore.org/pkg/server"
|
||||
)
|
||||
|
||||
// A Host is the environment hosting an importer.
|
||||
type Host struct {
|
||||
imp Importer
|
||||
|
||||
// target is the blobserver to populate.
|
||||
target blobserver.StatReceiver
|
||||
|
||||
search *search.Handler
|
||||
|
||||
// client optionally specifies how to fetch external network
|
||||
|
@ -190,8 +189,24 @@ func Create(name string, hl blobserver.Loader, cfg jsonconfig.Obj) (*Host, error
|
|||
}
|
||||
h := &Host{
|
||||
imp: imp,
|
||||
// TODO: get search & blobserver from the HandlerLoader
|
||||
// via the "root" type.
|
||||
}
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func (h *Host) InitHandler(hl blobserver.FindHandlerByTyper) error {
|
||||
_, handler, err := hl.FindHandlerByType("root")
|
||||
if err != nil || handler == nil {
|
||||
return errors.New("importer requires a 'root' handler")
|
||||
}
|
||||
rh := handler.(*server.RootHandler)
|
||||
searchHandler, ok := rh.SearchHandler()
|
||||
if !ok {
|
||||
return errors.New("importer requires a 'root' handler with 'searchRoot' defined.")
|
||||
}
|
||||
h.search = searchHandler
|
||||
if rh.Storage == nil {
|
||||
return errors.New("importer requires a 'root' handler with 'blobRoot' defined.")
|
||||
}
|
||||
h.target = rh.Storage
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -425,6 +425,16 @@ func (config *Config) InstallHandlers(hi HandlerInstaller, baseURL string, conte
|
|||
}
|
||||
hl.setupAll()
|
||||
|
||||
// Now that everything is setup, run any handlers' InitHandler
|
||||
// methods.
|
||||
for pfx, handler := range hl.handler {
|
||||
if in, ok := handler.(blobserver.HandlerIniter); ok {
|
||||
if err := in.InitHandler(hl); err != nil {
|
||||
return nil, fmt.Errorf("Error calling InitHandler on %s: %v", pfx, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if v, _ := strconv.ParseBool(os.Getenv("CAMLI_HTTP_EXPVAR")); v {
|
||||
hi.Handle("/debug/vars", expvarHandler{})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue