| 50 | } |
| 51 | |
| 52 | func convertPathToURL(path string, baseDir string, baseURL *url.URL) (string, error) { |
| 53 | relPath, err := filepath.Rel(baseDir, path) |
| 54 | if err != nil { |
| 55 | return "", fmt.Errorf("Cannot make relative path for %q: %v", path, err) |
| 56 | } |
| 57 | var result *url.URL |
| 58 | if baseURL != nil { |
| 59 | result, err = baseURL.Parse(filepath.ToSlash(relPath)) |
| 60 | } else { |
| 61 | result, err = url.Parse(filepath.ToSlash(relPath)) |
| 62 | } |
| 63 | if err != nil { |
| 64 | return "", fmt.Errorf("Failed to construct URL for %s. err: %v", path, err) |
| 65 | } |
| 66 | return result.String(), nil |
| 67 | } |
| 68 | |
| 69 | // responseWriter implements http.ResponseWriter. |
| 70 | type responseWriter struct { |