(pathElements ...string)
| 31 | } |
| 32 | |
| 33 | func (f httpFetcher) File(pathElements ...string) ([]byte, error) { |
| 34 | if len(pathElements) == 0 { |
| 35 | return nil, errFilenameNotSpecified.New() |
| 36 | } |
| 37 | |
| 38 | start := time.Now() |
| 39 | |
| 40 | p := path.Join(pathElements...) |
| 41 | url, err := realURLPath(f.root, p) |
| 42 | if err != nil { |
| 43 | return nil, err |
| 44 | } |
| 45 | |
| 46 | resp, err := f.httpClient.Get(url) |
| 47 | if err != nil { |
| 48 | return nil, errCouldNotFetchFile.WithCause(err).WithAttributes("filename", p) |
| 49 | } |
| 50 | if err = errors.FromHTTP(resp); err != nil { |
| 51 | return nil, errCouldNotFetchFile.WithCause(err).WithAttributes("filename", p) |
| 52 | } |
| 53 | defer resp.Body.Close() |
| 54 | |
| 55 | result, err := io.ReadAll(resp.Body) |
| 56 | if err != nil { |
| 57 | return nil, errCouldNotReadFile.WithCause(err).WithAttributes("filename", p) |
| 58 | } |
| 59 | f.observeLatency(time.Since(start)) |
| 60 | return result, nil |
| 61 | } |
| 62 | |
| 63 | // FromHTTP returns an object to fetch files from a webserver. |
| 64 | func FromHTTP(client *http.Client, rootURL string) (Interface, error) { |
nothing calls this directly
no test coverage detected