本文整理汇总了Golang中camlistore/org/pkg/blobserver.FindHandlerByTyper类的典型用法代码示例。如果您正苦于以下问题:Golang FindHandlerByTyper类的具体用法?Golang FindHandlerByTyper怎么用?Golang FindHandlerByTyper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FindHandlerByTyper类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InitHandler
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
_, handler, _ = hl.FindHandlerByType("jsonsign")
if sigh, ok := handler.(*signhandler.Handler); ok {
h.signer = sigh.Signer()
}
if h.signer == nil {
return errors.New("importer requires a 'jsonsign' handler")
}
return nil
}
示例2: InitHandler
func (sh *SyncHandler) InitHandler(hl blobserver.FindHandlerByTyper) error {
_, h, err := hl.FindHandlerByType("root")
if err == blobserver.ErrHandlerTypeNotFound {
// It's optional. We register ourselves if it's there.
return nil
}
if err != nil {
return err
}
h.(*RootHandler).registerSyncHandler(sh)
return nil
}
示例3: InitHandler
// InitHandler sets the app handler's search handler, if the app handler was configured
// to have one with HasSearch.
func (a *Handler) InitHandler(hl blobserver.FindHandlerByTyper) error {
apName := a.ProgramName()
searchPrefix, _, err := hl.FindHandlerByType("search")
if err != nil {
return fmt.Errorf("No search handler configured, which is necessary for the %v app handler", apName)
}
var sh *search.Handler
_, hi := hl.AllHandlers()
h, ok := hi[searchPrefix]
if !ok {
return fmt.Errorf("failed to find the \"search\" handler for %v", apName)
}
sh = h.(*search.Handler)
a.sh = sh
return nil
}
示例4: InitHandler
func (h *Host) InitHandler(hl blobserver.FindHandlerByTyper) error {
if prefix, _, err := hl.FindHandlerByType("ui"); err == nil {
h.uiPrefix = prefix
}
_, 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
h.blobSource = rh.Storage
_, handler, _ = hl.FindHandlerByType("jsonsign")
if sigh, ok := handler.(*signhandler.Handler); ok {
h.signer = sigh.Signer()
}
if h.signer == nil {
return errors.New("importer requires a 'jsonsign' handler")
}
h.didInit.Done()
go h.startPeriodicImporters()
return nil
}
示例5: InitHandler
func (sh *StatusHandler) InitHandler(hl blobserver.FindHandlerByTyper) error {
_, h, err := hl.FindHandlerByType("search")
if err == blobserver.ErrHandlerTypeNotFound {
return nil
}
if err != nil {
return err
}
go func() {
var lastSend *status
for {
cur := sh.currentStatus()
if reflect.DeepEqual(cur, lastSend) {
// TODO: something better. get notified on interesting events.
time.Sleep(10 * time.Second)
continue
}
lastSend = cur
js, _ := json.MarshalIndent(cur, "", " ")
h.(*search.Handler).SendStatusUpdate(js)
}
}()
return nil
}
示例6: InitHandler
// InitHandler goes through all the other configured handlers to discover
// the publisher ones, and uses them to populate ui.publishRoots.
func (ui *UIHandler) InitHandler(hl blobserver.FindHandlerByTyper) error {
// InitHandler is called after all handlers have been setup, so the bootstrap
// of the camliRoot node for publishers in dev-mode is already done.
searchPrefix, _, err := hl.FindHandlerByType("search")
if err != nil {
return errors.New("No search handler configured, which is necessary for the ui handler")
}
var sh *search.Handler
htype, hi := hl.AllHandlers()
if h, ok := hi[searchPrefix]; !ok {
return errors.New("failed to find the \"search\" handler")
} else {
sh = h.(*search.Handler)
ui.search = sh
}
camliRootQuery := func(camliRoot string) (*search.SearchResult, error) {
return sh.Query(&search.SearchQuery{
Limit: 1,
Constraint: &search.Constraint{
Permanode: &search.PermanodeConstraint{
Attr: "camliRoot",
Value: camliRoot,
},
},
})
}
for prefix, typ := range htype {
if typ != "app" {
continue
}
ah, ok := hi[prefix].(*app.Handler)
if !ok {
panic(fmt.Sprintf("UI: handler for %v has type \"app\" but is not app.Handler", prefix))
}
if ah.ProgramName() != "publisher" {
continue
}
appConfig := ah.AppConfig()
if appConfig == nil {
log.Printf("UI: app handler for %v has no appConfig", prefix)
continue
}
camliRoot, ok := appConfig["camliRoot"].(string)
if !ok {
log.Printf("UI: camliRoot in appConfig is %T, want string", appConfig["camliRoot"])
continue
}
result, err := camliRootQuery(camliRoot)
if err != nil {
log.Printf("UI: could not find permanode for camliRoot %v: %v", camliRoot, err)
continue
}
if len(result.Blobs) == 0 || !result.Blobs[0].Blob.Valid() {
log.Printf("UI: no valid permanode for camliRoot %v", camliRoot)
continue
}
if ui.publishRoots == nil {
ui.publishRoots = make(map[string]*publishRoot)
}
ui.publishRoots[prefix] = &publishRoot{
Name: camliRoot,
Prefix: prefix,
Permanode: result.Blobs[0].Blob,
}
}
return nil
}