(prefix string)
| 275 | } |
| 276 | |
| 277 | func (hl *handlerLoader) setupHandler(prefix string) { |
| 278 | h, ok := hl.config[prefix] |
| 279 | if !ok { |
| 280 | exitFailure("invalid reference to undefined handler %q", prefix) |
| 281 | } |
| 282 | if h.setupDone { |
| 283 | // Already setup by something else reference it and forcing it to be |
| 284 | // setup before the bottom loop got to it. |
| 285 | return |
| 286 | } |
| 287 | hl.prefixStack = append(hl.prefixStack, prefix) |
| 288 | if h.settingUp { |
| 289 | buf := make([]byte, 1024) |
| 290 | buf = buf[:runtime.Stack(buf, false)] |
| 291 | exitFailure("loop in configuration graph; %q tried to load itself indirectly: %q\nStack:\n%s", |
| 292 | prefix, hl.prefixStack, buf) |
| 293 | } |
| 294 | h.settingUp = true |
| 295 | defer func() { |
| 296 | // log.Printf("Configured handler %q", prefix) |
| 297 | h.setupDone = true |
| 298 | hl.prefixStack = hl.prefixStack[:len(hl.prefixStack)-1] |
| 299 | r := recover() |
| 300 | if r == nil { |
| 301 | if hl.handler[prefix] == nil { |
| 302 | panic(fmt.Sprintf("setupHandler for %q didn't install a handler", prefix)) |
| 303 | } |
| 304 | } else { |
| 305 | panic(r) |
| 306 | } |
| 307 | }() |
| 308 | |
| 309 | hl.curPrefix = prefix |
| 310 | |
| 311 | if strings.HasPrefix(h.htype, "storage-") { |
| 312 | // Assume a storage interface: |
| 313 | stype := strings.TrimPrefix(h.htype, "storage-") |
| 314 | pstorage, err := blobserver.CreateStorage(stype, hl, h.conf) |
| 315 | if err != nil { |
| 316 | exitFailure("error instantiating storage for prefix %q, type %q: %v", |
| 317 | h.prefix, stype, err) |
| 318 | } |
| 319 | if ix, ok := pstorage.(*index.Index); ok && ix.WantsReindex() { |
| 320 | log.Printf("Reindexing %s ...", h.prefix) |
| 321 | if err := ix.Reindex(); err != nil { |
| 322 | if ix.WantsKeepGoing() { |
| 323 | log.Printf("Error reindexing %s: %v", h.prefix, err) |
| 324 | } else { |
| 325 | exitFailure("Error reindexing %s: %v", h.prefix, err) |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | hl.handler[h.prefix] = pstorage |
| 330 | if h.internal { |
| 331 | hl.installer.Handle(prefix, unauthorizedHandler{}) |
| 332 | } else { |
| 333 | hl.installer.Handle(prefix+"camli/", makeCamliHandler(prefix, hl.baseURL, pstorage, hl)) |
| 334 | } |
no test coverage detected