https://github.com/moriyoshi/simplefiletx
A (non-hurting) file protocol handler implementation for Go's net.http.
https://github.com/moriyoshi/simplefiletx
file golang http transport url
Last synced: 8 months ago
JSON representation
A (non-hurting) file protocol handler implementation for Go's net.http.
- Host: GitHub
- URL: https://github.com/moriyoshi/simplefiletx
- Owner: moriyoshi
- Created: 2018-05-28T09:28:48.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-02-02T05:17:35.000Z (about 7 years ago)
- Last Synced: 2025-03-07T02:49:08.031Z (about 1 year ago)
- Topics: file, golang, http, transport, url
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## simplefiletx
[](https://godoc.org/github.com/moriyoshi/simplefiletx)
[](https://travis-ci.com/moriyoshi/simplefiletx)
simplefiletx is a protocol handler implementation for Go's `net.http`.
In contrast to Go's standard `FileTransport` implementation, it does:
* Handle relative file paths like
`file:foo/bar/relative`
(Although the form violates RFC8089, it'd been quite common before the standard got out the door)
And it does **not**:
* Automatically render the directory content as HTML
* Or try to find `index.html` under the directory and return its content
when the resolved path corresponds to a directory in the filesystem.
(This is pretty much not desired behavior when it comes to simply using URLs as an universal way to describe the resource location)
### Synopsis
```golang
import "github.com/moriyoshi/simplefiletx"
tx := &http.Transport{}
tx.RegisterProtocol("file", simplefiletx.NewSimpleFileTransport("/somewhere-in-the-filesystem"))
c := &http.Client{Transport: tx}
resp, err := c.Get("file:/test.txt") // try to fetch "/test.txt"
resp, err := c.Get("file:///test.txt") // try to fetch "/test.txt"
resp, err := c.Get("file://localhost/test.txt") // try to fetch "/test.txt"
resp, err := c.Get("file:test.txt") // try to fetch "/somewhere-in-the-filesystem/test.txt"
```
### License
MIT