Documentation

Overview

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

Example

Code:

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))
}

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

Code:

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))
}

func WithBasePath

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

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