fetch

package
v0.0.0-...-5352646 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

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"

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

func main() {
	fetcher, err := fetch.FromHTTP("http://webserver.thethings.network/repository", true)
	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(rootURL string, cache bool) (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/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