2 Star 8 Fork 6

user_499098 / imgproxy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fs_transport.go 768 Bytes
一键复制 编辑 原始数据 按行查看 历史
DarthSim 提交于 2019-02-04 20:04 . Simple filesystem transport
package main
import (
"fmt"
"net/http"
)
type fsTransport struct {
fs http.Dir
}
func newFsTransport() fsTransport {
return fsTransport{fs: http.Dir(conf.LocalFileSystemRoot)}
}
func (t fsTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
f, err := t.fs.Open(req.URL.Path)
if err != nil {
return nil, err
}
fi, err := f.Stat()
if err != nil {
return nil, err
}
if fi.IsDir() {
return nil, fmt.Errorf("%s is a directory", req.URL.Path)
}
return &http.Response{
Status: "200 OK",
StatusCode: 200,
Proto: "HTTP/1.0",
ProtoMajor: 1,
ProtoMinor: 0,
Header: make(http.Header),
ContentLength: fi.Size(),
Body: f,
Close: true,
Request: req,
}, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yunwisdoms/imgproxy.git
git@gitee.com:yunwisdoms/imgproxy.git
yunwisdoms
imgproxy
imgproxy
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891