(prefix string, optionProvider func(path string) (*FileHandlerOption, error))
| 449 | } |
| 450 | |
| 451 | func (c *Client) RegisterFilePrefixHandler(prefix string, optionProvider func(path string) (*FileHandlerOption, error)) { |
| 452 | c.UrlHandlerMux.PathPrefix(prefix).HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 453 | option, err := optionProvider(r.URL.Path) |
| 454 | if err != nil { |
| 455 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 456 | return |
| 457 | } |
| 458 | if option == nil { |
| 459 | http.Error(w, "no content available", http.StatusNotFound) |
| 460 | return |
| 461 | } |
| 462 | if err := ServeFileOption(w, r, *option); err != nil { |
| 463 | http.Error(w, fmt.Sprintf("Failed to serve content: %v", err), http.StatusInternalServerError) |
| 464 | } |
| 465 | }) |
| 466 | } |
| 467 | |
| 468 | func (c *Client) RegisterFileHandler(path string, option FileHandlerOption) { |
| 469 | c.UrlHandlerMux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected