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

Method Fetcher

pkg/config/shared.go:349–390  ·  view source on GitHub ↗

Fetcher returns a fetch.Interface based on the configuration. If no configuration source is set, this method returns nil, nil.

(
	ctx context.Context, blobConf BlobConfig, httpClientProvider httpclient.Provider,
)

Source from the content-addressed store, hash-verified

347// Fetcher returns a fetch.Interface based on the configuration.
348// If no configuration source is set, this method returns nil, nil.
349func (c FrequencyPlansConfig) Fetcher(
350 ctx context.Context, blobConf BlobConfig, httpClientProvider httpclient.Provider,
351) (fetch.Interface, error) {
352 // TODO: Remove detection mechanism (https://github.com/TheThingsNetwork/lorawan-stack/issues/1450)
353 configSource := c.ConfigSource
354 if configSource == "" {
355 switch {
356 case c.Static != nil:
357 configSource = "static"
358 case c.Directory != "":
359 if stat, err := os.Stat(c.Directory); err == nil && stat.IsDir() {
360 configSource = "directory"
361 break
362 }
363 fallthrough
364 case c.URL != "":
365 configSource = "url"
366 case !c.Blob.IsZero():
367 configSource = "blob"
368 }
369 }
370 switch configSource {
371 case "static":
372 return fetch.NewMemFetcher(c.Static), nil
373 case "directory":
374 return fetch.FromFilesystem(c.Directory), nil
375 case "url":
376 httpClient, err := httpClientProvider.HTTPClient(ctx, httpclient.WithCache(true))
377 if err != nil {
378 return nil, err
379 }
380 return fetch.FromHTTP(httpClient, c.URL)
381 case "blob":
382 b, err := blobConf.Bucket(ctx, c.Blob.Bucket, httpClientProvider)
383 if err != nil {
384 return nil, err
385 }
386 return fetch.FromBucket(ctx, b, c.Blob.Path), nil
387 default:
388 return nil, nil
389 }
390}
391
392// InteropClient represents the client-side interoperability through LoRaWAN Backend Interfaces configuration.
393type InteropClient struct {

Callers 2

TestWebFunction · 0.95
TestGRPCFunction · 0.95

Calls 8

NewMemFetcherFunction · 0.92
FromFilesystemFunction · 0.92
WithCacheFunction · 0.92
FromHTTPFunction · 0.92
FromBucketFunction · 0.92
BucketMethod · 0.80
IsZeroMethod · 0.65
HTTPClientMethod · 0.65

Tested by 2

TestWebFunction · 0.76
TestGRPCFunction · 0.76