fetch

package
v3.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2022 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package fetch offers abstractions to fetch a file with the same method, regardless of a location (filesystem, HTTP...).

Example
package main

import (
	"fmt"
	"net/http"

	"go.thethings.network/lorawan-stack/v3/pkg/fetch"
)

func main() {
	fetcher, err := fetch.FromHTTP(http.DefaultClient, "http://webserver.thethings.network/repository")
	if err != nil {
		panic(err)
	}
	content, err := fetcher.File("README.md")
	if err != nil {
		panic(err)
	}

	fmt.Println("Content of http://webserver.thethings.network/repository/README.md:")
	fmt.Println(string(content))
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	File(pathElements ...string) ([]byte, error)
}

Interface is an abstraction for file retrieval.

func FromBucket

func FromBucket(ctx context.Context, bucket *blob.Bucket, root string) Interface

FromBucket returns an interface that fetches files from the given blob bucket.

func FromFilesystem

func FromFilesystem(rootElements ...string) Interface

FromFilesystem returns an interface that fetches files from the local filesystem.

func FromHTTP

func FromHTTP(client *http.Client, rootURL string) (Interface, error)

FromHTTP returns an object to fetch files from a webserver.

func NewMemFetcher

func NewMemFetcher(store map[string][]byte) Interface

NewMemFetcher initializes a new memory fetcher.

Example
package main

import (
	"fmt"

	"go.thethings.network/lorawan-stack/v3/pkg/fetch"
)

func main() {
	fetcher := fetch.NewMemFetcher(map[string][]byte{
		"file.txt":     []byte("content"),
		"dir/file.txt": []byte("content"),
	})
	content, err := fetcher.File("dir/file.txt")
	if err != nil {
		panic(err)
	}

	fmt.Println("Content of myFile.yml")
	fmt.Println(string(content))
}
Output:

func WithBasePath

func WithBasePath(f Interface, basePath ...string) Interface

WithBasePath returns an Interface, which preprends basePath to non-absolute requested paths.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL