InitHandler goes through all the other configured handlers to discover the publisher ones, and uses them to populate ui.publishRoots.
(hl blobserver.FindHandlerByTyper)
| 256 | // InitHandler goes through all the other configured handlers to discover |
| 257 | // the publisher ones, and uses them to populate ui.publishRoots. |
| 258 | func (ui *UIHandler) InitHandler(hl blobserver.FindHandlerByTyper) error { |
| 259 | // InitHandler is called after all handlers have been setup, so the bootstrap |
| 260 | // of the camliRoot node for publishers in dev-mode is already done. |
| 261 | searchPrefix, _, err := hl.FindHandlerByType("search") |
| 262 | if err != nil { |
| 263 | return errors.New("No search handler configured, which is necessary for the ui handler") |
| 264 | } |
| 265 | var sh *search.Handler |
| 266 | htype, hi := hl.AllHandlers() |
| 267 | if h, ok := hi[searchPrefix]; !ok { |
| 268 | return errors.New("failed to find the \"search\" handler") |
| 269 | } else { |
| 270 | sh = h.(*search.Handler) |
| 271 | ui.search = sh |
| 272 | } |
| 273 | camliRootQuery := func(camliRoot string) (*search.SearchResult, error) { |
| 274 | return sh.Query(context.TODO(), &search.SearchQuery{ |
| 275 | Limit: 1, |
| 276 | Constraint: &search.Constraint{ |
| 277 | Permanode: &search.PermanodeConstraint{ |
| 278 | Attr: "camliRoot", |
| 279 | Value: camliRoot, |
| 280 | }, |
| 281 | }, |
| 282 | }) |
| 283 | } |
| 284 | for prefix, typ := range htype { |
| 285 | if typ != "app" { |
| 286 | continue |
| 287 | } |
| 288 | ah, ok := hi[prefix].(*app.Handler) |
| 289 | if !ok { |
| 290 | panic(fmt.Sprintf("UI: handler for %v has type \"app\" but is not app.Handler", prefix)) |
| 291 | } |
| 292 | // TODO(mpl): this check is weak, as the user could very well |
| 293 | // use another binary name for the publisher app. We should |
| 294 | // introduce/use another identifier. |
| 295 | if ah.ProgramName() != "publisher" { |
| 296 | continue |
| 297 | } |
| 298 | appConfig := ah.AppConfig() |
| 299 | if appConfig == nil { |
| 300 | log.Printf("UI: app handler for %v has no appConfig", prefix) |
| 301 | continue |
| 302 | } |
| 303 | camliRoot, ok := appConfig["camliRoot"].(string) |
| 304 | if !ok { |
| 305 | log.Printf("UI: camliRoot in appConfig is %T, want string", appConfig["camliRoot"]) |
| 306 | continue |
| 307 | } |
| 308 | result, err := camliRootQuery(camliRoot) |
| 309 | if err != nil { |
| 310 | log.Printf("UI: could not find permanode for camliRoot %v: %v", camliRoot, err) |
| 311 | continue |
| 312 | } |
| 313 | if len(result.Blobs) == 0 || !result.Blobs[0].Blob.Valid() { |
| 314 | log.Printf("UI: no valid permanode for camliRoot %v", camliRoot) |
| 315 | continue |
nothing calls this directly
no test coverage detected