serveFromDiskOrStatic matches rx against req's path and serves the match either from disk (if non-nil) or from static (embedded in the binary).
(rw http.ResponseWriter, req *http.Request, rx *regexp.Regexp, disk http.Handler, static fs.FS)
| 629 | |
| 630 | // serveFromDiskOrStatic matches rx against req's path and serves the match either from disk (if non-nil) or from static (embedded in the binary). |
| 631 | func (ui *UIHandler) serveFromDiskOrStatic(rw http.ResponseWriter, req *http.Request, rx *regexp.Regexp, |
| 632 | disk http.Handler, static fs.FS) { |
| 633 | suffix := httputil.PathSuffix(req) |
| 634 | m := rx.FindStringSubmatch(suffix) |
| 635 | if m == nil { |
| 636 | panic("Caller should verify that rx matches") |
| 637 | } |
| 638 | file := m[1] |
| 639 | if disk != nil { |
| 640 | req.URL.Path = "/" + file |
| 641 | disk.ServeHTTP(rw, req) |
| 642 | } else { |
| 643 | ServeStaticFile(rw, req, static, file) |
| 644 | } |
| 645 | |
| 646 | } |
| 647 | |
| 648 | func (ui *UIHandler) serveQR(rw http.ResponseWriter, req *http.Request) { |
| 649 | url := req.URL.Query().Get("url") |
no test coverage detected