MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / File

Method File

pkg/fetch/http.go:33–61  ·  view source on GitHub ↗
(pathElements ...string)

Source from the content-addressed store, hash-verified

31}
32
33func (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.
64func FromHTTP(client *http.Client, rootURL string) (Interface, error) {

Callers

nothing calls this directly

Calls 10

FromHTTPFunction · 0.92
realURLPathFunction · 0.85
observeLatencyMethod · 0.80
NewMethod · 0.65
NowMethod · 0.65
JoinMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65
WithAttributesMethod · 0.45
WithCauseMethod · 0.45

Tested by

no test coverage detected