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 ¶
- type Interface
- func FromBucket(ctx context.Context, bucket *blob.Bucket, root string) Interface
- func FromFilesystem(rootElements ...string) Interface
- func FromHTTP(client *http.Client, rootURL string) (Interface, error)
- func NewMemFetcher(store map[string][]byte) Interface
- func WithBasePath(f Interface, basePath ...string) Interface
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interface ¶
Interface is an abstraction for file retrieval.
func FromBucket ¶
FromBucket returns an interface that fetches files from the given blob bucket.
func FromFilesystem ¶
FromFilesystem returns an interface that fetches files from the local filesystem.
func NewMemFetcher ¶
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 ¶
WithBasePath returns an Interface, which preprends basePath to non-absolute requested paths.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.