Skip to content

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

License

Notifications You must be signed in to change notification settings

pencil/go-httpfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages