1 Star 0 Fork 0

TGodfather / misc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
httpfs.go 642 Bytes
一键复制 编辑 原始数据 按行查看 历史
zhuokang_tan 提交于 2022-09-27 18:03 . webcenter:modify\n httpfs:add
package httpfs
import (
"io/fs"
"net/http"
"strings"
)
//http file system
type HFS struct {
fs http.FileSystem
opts HfsOptions
}
func NewHFS(fsys fs.FS, opt ...HfsOption) *HFS {
opts := HfsOptions{
pathPrefix: "",
indexName: "index.html",
}
for _, o := range opt {
o(&opts)
}
hfs := &HFS{
fs: http.FS(fsys),
opts: opts,
}
return hfs
}
func (h *HFS) Open(name string) (http.File, error) {
if name == "/" {
//name = "."
name = h.opts.indexName
} else {
name = strings.TrimPrefix(name, "/")
}
newName := h.opts.pathPrefix + name
//log.Println("HFS open", name, newName)
return h.fs.Open(newName)
}
Go
1
https://gitee.com/tgodfather/misc.git
git@gitee.com:tgodfather/misc.git
tgodfather
misc
misc
4dc1fac3246d

搜索帮助