go-httpfs

module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: MIT

README

go-httpfs

An fs.FS implementation that reads files from an HTTP backend.

Usage

package main

import (
	"io"
	"io/fs"
	"log"
	"net/http"
	"net/url"

	"github.com/pencil/go-httpfs/httpfs"
)

func main() {
	baseURL, _ := url.Parse("http://localhost:3000/data/")
	var store fs.FS
	store = httpfs.New(http.DefaultClient, baseURL)

	file, err := store.Open("test.txt") // requests http://localhost:3000/data/test.txt
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	data, err := io.ReadAll(file)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("%s", data)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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