fetch

package
v3.0.0-pre.0...-f1e8a59 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

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

Example
fetcher := FromHTTP("http://webserver.thethings.network/repository", true)
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 FromFilesystem

func FromFilesystem(basePath string) Interface

FromFilesystem returns an interface that fetches files from the local filesystem

func FromHTTP

func FromHTTP(baseURL string, cache bool) Interface

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{
		"myFile.yml": []byte("Content"),
	})
	content, err := fetcher.File("myFile.yml")
	if err != nil {
		panic(err)
	}

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

Jump to

Keyboard shortcuts

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